\documentclass[xcolor=hyperref,hyperef={naturalnames,pdfpagelabels},french]{beamer}
\usepackage{etex}
\usepackage[beamer]{preambule}
\usepackage[french,vlined,boxed]{algorithm2e}
\usepackage{bookmark}
\usepackage{movie15}
%\usepackage{multimedia}
% \usepackage{cclicenses}
% \usepackage{cclicence}


\setlength{\columnseprule}{0pt}

\graphicspath{{/home/moi/Lycee/2nde/2009_10/}{/home/moi/Photos/Maths/}{/home/moi/Figures/FigSTI/}{/home/moi/Figures/FigSeconde/}{/home/moi/Figures/figuresTS/}{/home/moi/Lycee/TDmaple/2007_8/}{/home/moi/IREM/IREM10_06_09/}}



\newcommand\xc{\lstset{numbers=none,language=XCAS,xleftmargin=10pt,%
keywordstyle =\color{orange!40}\usefont{OT1}{cmtt}{b}{n},basicstyle=\ttfamily\color{white},commentstyle=\normalfont\scriptsize\slshape,breaklines=true,backgroundcolor=\color{black!90!red},frame=trBL,framerule=1pt,framesep=4pt,rulesep=1pt,showstringspaces=false,stringstyle=\slshape,captionpos=b}
}


\newcommand\caml{
\lstset{numbers=none,language=Caml,xleftmargin=10pt,%
keywordstyle =\color{blue!40}\usefont{OT1}{cmtt}{b}{n},basicstyle=\ttfamily\color{white},commentstyle=\normalfont\scriptsize\slshape,breaklines=true,backgroundcolor=\color{black!90!blue},frame=trBL,framerule=1pt,framesep=4pt,rulesep=1pt,showstringspaces=false,stringstyle=\slshape,captionpos=b}
}
\renewcommand\FancyVerbFormatLine[1]{\colorbox{green}{#1}}



\newcommand{\reponse}[1]{
\begin{center}
\textcolor{blue!70}{\texttt{#1}}
\end{center}
}





\mode<presentation>
{
  \usetheme[secheader]{Madrid}
  % or ...Warsaw

  \setbeamercovered{highly dynamic}
  % or whatever (possibly just delete it)
}
\usepackage{elephantbird}

\title[] % (optional, use only with long paper titles)
{Algorithmes en analyse}

\subtitle{ Illustrations avec XCAS et CAML}

\author[] % (optional, use only with lots of authors)
{Guillaume CONNAN  }
% - Give the names in the same order as the appear in the paper.
% - Use the inst{?} command only if the authors have different
%   affiliation.

\institute{\textsc{IREM} de Nantes}% (optional, but mostly needed)

\logo{\includegraphics[scale=0.15]{logoirem}}

\date[] % (optional, should be abbreviation of conference name)
{\today}
% - Either use conference name or its abbreviation.
% - Not really informative to the audience, more for people (including
%   yourself) who are reading the slides online

\subject{Algorithmes en analyse}


\beamerdefaultoverlayspecification{<+->}

\AtBeginSubsubsection[]
{
  \begin{frame}<beamer>
    \frametitle{Sommaire}
 {\scriptsize
\begin{multicols}{2}
    \tableofcontents[currentsection,currentsubsection]
       \end{multicols}
}

  \end{frame}
}




\AtBeginSubsection[]
{
  \begin{frame}<beamer>
    \frametitle{Sommaire}
 {\scriptsize
\begin{multicols}{2}
    \tableofcontents[currentsection,currentsubsection]
       \end{multicols}
}

  \end{frame}
}





\AtBeginSection[]
{
  \begin{frame}<beamer>
    \frametitle{Sommaire}
 {\scriptsize
\begin{multicols}{2}
    \tableofcontents[currentsection]
       \end{multicols}
}

  \end{frame}
}


% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command: 

\beamerdefaultoverlayspecification{<+->}


\usepackage[scaled]{helvet} % With " scaled " option
\usepackage{eulervm} %


\begin{document}


\begin{frame}
  \titlepage
\end{frame}

\begin{frame}
 \frametitle{Sommaire}
{\scriptsize
\begin{multicols}{2} 
 \tableofcontents
\end{multicols}
}

 
 \end{frame}



\section{Les réels et le processeur}



\begin{frame}
  
Ayez toujours en  tête qu'un ordinateur ne peut  pas travailler avec des
réels~! 

\pause

Par  essence, il a un nombre  fini de bits sur  lesquels il peut
coder des nombres...
\end{frame}

\begin{frame}
  Les nombres \textit{flottants} qu'il  manipule sont donc des classes qui
représentent chacune une infinité de  réels (mais tout en constituant un
intervalle cohérent).
\end{frame}



\begin{frame}
  Si on n'y fait pas attention, cela peut créer des surprises...
\end{frame}


\begin{frame}[fragile]
\xc
Entrons trois nombres sur XCAS~:

\begin{lstlisting}
x:=10;
y:=-5;
z:=5.00000001;
\end{lstlisting}

\end{frame}


\begin{frame}[fragile]
\xc

Alors~:

\begin{lstlisting}
(x*y)+(x*z)
\end{lstlisting}

renvoie~:

\reponse{1.000000012e-07}


\pause



Mais 

\begin{lstlisting}
x*(y+z)
\end{lstlisting}


renvoie~:

\reponse{9.999999939e-08}



\end{frame}





\begin{frame}[fragile]
             \caml

Le problème est le même avec CAML~:

\caml

\begin{lstlisting}
# let x,y,z=10.,-5.,5.00000001;;
val x : float = 10.
val y : float = -5.
val z : float = 5.00000001

# (x*.y)+.(x*.z);;
- : float = 1.00000001168609742e-07

# x*.(y+.z);;
- : float = 9.99999993922529e-08
\end{lstlisting}


\end{frame}




\begin{frame}
  
Ainsi l'addition  n'est pas toujours distributive  sur la multiplication
quand on travaille sur les flottants~!

\pause

Ces petites erreurs qui s'accumulent peuvent en créer de grandes~! 

\end{frame}



\begin{frame}[fragile]
  Créons  une fonction  qui renvoie  l'approximation de  la  dérivée d'une
fonction en un nombre donné avec un \og \verb+dx+\fg{} valant $10^{-10}$~:

\end{frame}




\begin{frame}[fragile]
             \caml
              
\begin{lstlisting}
# let dernum(f)=function
          x->(f(x+.0.0000000001)-.f(x))/.0.0000000001;;
\end{lstlisting}


\pause

Dérivons le sinus  cinq fois de suite et évaluons  la fonction obtenue en
0~:

\begin{lstlisting}
# dernum(dernum(dernum(dernum(dernum(sin)))))(0.);;
- : float = -1.33226762955018773e+25
\end{lstlisting}
\end{frame}




\section{Tracé de représentations graphiques}


\subsection{Version récursive à pas constant}



\begin{frame}[fragile]
\xc
On a créé une liste de coordonnées du type $(x,f(x))$ avec un pas de $h$
entre $a$ et $b$.

\pause

\begin{lstlisting}
liste_points(f,a,b,h):={
if(a>b)then{[b,f(b)]}
else{[a,f(a)],liste_points(f,a+h,b,h)}
}:;
\end{lstlisting}

\end{frame}


\begin{frame}[fragile]
\xc

On relie ces points par des segments avec \texttt{polygonplot(liste de coordonnées)}~:

\pause

\begin{lstlisting}
graph(f,a,b,h):={
polygonplot([liste_points(f,a,b,h)])
}:;
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\xc

Par exemple, on trace la fonction carrée entre $-2$ et 2 avec un pas de $0,75$~:


\begin{lstlisting}
graph(x->x^2,-2,2,0.75)
\end{lstlisting}

\end{frame}


\begin{frame}

\begin{figure}
\begin{center}
  \includegraphics[width=0.8\textwidth,height=0.8\textheight]{carre}
\end{center}
\end{figure}  
\end{frame}






\subsection{Version récursive par sondage aléatoire}



\begin{frame}
  
On  interroge au hasard  un réel  et on  lui demande  son image  par une
certaine fonction~:~cela  nous permettra-t-il d'avoir une  bonne idée de
l'allure de la courbe~? 

\end{frame}



\begin{frame}[fragile]
\xc
 

\begin{lstlisting}
liste_points_hasard(f,a,a0,b,n):={
if(n==0)then{[b,f(b)]}
else{[a0,f(a0)],liste_points_hasard(f,a,a+rand(0,1)*(b-a),b,n-1)}
}:;
\end{lstlisting}


\end{frame}





\begin{frame}[fragile]
\xc
 
\begin{lstlisting}
graph_hasard(f,a,b,n):={
polygonplot([liste_points_hasard(f,a,a,b,n)])
}:;
\end{lstlisting}


Alors on obtient pour la fonction sinus entre $-5$ et $5$ avec $8$ \og sondés\fg{}~:

\begin{lstlisting}
graph_hasard(x->sin(x),-5,5,8)
\end{lstlisting}

\end{frame}




\begin{frame}
  \begin{figure}
\begin{center}
  \includegraphics[width=0.8\textwidth,height=0.8\textheight]{sinhasard}
\end{center}
\end{figure}  
\end{frame}



\section{Fonctions définies par morceaux}



\begin{frame}
  
Comment faire dessiner une courbe en dents de scie, chaque dent ayant une
largeur  de  2  et  une  hauteur  de  1~?   Peut-on  avoir  une  formule
explicite qui permette de calculer l'image de n'importe quel nombre~?

\pause

Les coefficients directeurs valent alternativement $1$ et $-1$.

\pause

Les ordonnées s'annulent aux points d'abscisses paires...

\end{frame}



\begin{frame}[fragile]
\xc
\begin{lstlisting}
scie_rec(n):={
if(n==0)then{[0,0]}
  else{[n,(1-(-1)^n)/2],scie_rec(n-1)}  
}:;
\end{lstlisting}



\pause



\begin{lstlisting}
scie(n):={
polygonplot([scie_rec(n)])
}:;
\end{lstlisting}

\end{frame}



\begin{frame}
  \begin{figure}
\begin{center}
  \includegraphics[width=0.8\textwidth,height=0.8\textheight]{scie1}
\end{center}
\end{figure}  
\end{frame}



\begin{frame}[fragile]
\xc
 
Le tracé a été obtenu sans formule explicite pour chaque réel. Cherchons
une telle formulation~:

\pause

\begin{lstlisting}
f(x):={
   if(irem(floor(x),2)==0)
      then{x-floor(x)}
      else{1-x+floor(x)}
}:;
\end{lstlisting}

\pause

sachant que  \texttt{floor} donne la partie entière  et \texttt{irem} le
reste de la division euclidienne.
\end{frame}




\section{Recherche de minimum}



\begin{frame}
 
On repère graphiquement qu'une  fonction semble atteindre par exemple un
minimum. Pour  obtenir une  approximation de ce  minimum, on  fournit un
point de départ et une précision.


\end{frame}




\subsection{Version récursive}


\begin{frame}[fragile]
             \caml
             

En CAML~:


\caml

\begin{lstlisting}
# let rec min_rec(f,xo,h)=
    if f(xo+.h)>f(xo) then xo
    else min_rec(f,xo+.h,h);;
\end{lstlisting}


\end{frame}



\begin{frame}[fragile]
\xc
 
En XCAS~:

\begin{lstlisting}
min_rec(f,xo,h):={
if(f(xo+h)>f(xo)){return(xo)}
else{min_rec(f,xo+h,h)}
}
\end{lstlisting}


\end{frame}







\subsection{Version impérative}





\begin{frame}[fragile]
              

\begin{algorithm}[H]
\Entree{fonction f, point de départ xo et incrément i}
\Ini{
Y\aff f(xo)
X\aff xo+i
}
\Deb{
\Tq{t(X)<Y}{
Y\aff evalf(t(X))
X\aff X+i
}
\Retour{X-i}
 } 
\end{algorithm}
\end{frame}


\begin{frame}[fragile]
\xc
 

\begin{lstlisting}
minimum(f,xo,p):={
local X,Y,compteur;
Y:=f(xo);
X:=xo+10^(-p);
compteur:=0 // on rajoute un compteur pour que la compilation ne dure pas trop longtemps
tantque evalf(f(X))<Y et compteur<10^p faire 
    Y:=evalf(f(X)); 
    X:=X+10^(-p);
    compteur:=compteur+1; 
ftantque:;
 X-10^(-p);
}:;
\end{lstlisting}

\end{frame}





\begin{frame}[fragile]
\xc
 


Par            exemple,            pour           la            fonction
$x\mapsto\sqrt{x^{2}+25}+\sqrt{\left(x-18\right)^{2}+49}  $,  il  semble
que le minimum soit vers 7.

\pause

Demandons une approximation du minimum à $10^{-5}$ près~:

\begin{lstlisting}
minimum(x->sqrt((x)^2+25)+sqrt((x-18)^2+49),7.0,5)
\end{lstlisting}


\pause

et on obtient 7.50000

\end{frame}



\subsection{Avec affinage progressif du pas}


\begin{frame}
  
On  peut   améliorer  la  situation   en  affinant  petit  à   petit  le
balayage~:~d'abord $h$ puis $h/10$, etc.

\end{frame}

\begin{frame}[fragile]
             \caml
              

Avec CAML~:


\begin{lstlisting}
# let rec min_bis(f,xo,h,p)=
  if abs_float(h)<p then xo
  else if f(xo+.h)>f(xo)
       then min_bis(f,xo,-.0.1*.h,p)
       else min_bis(f,xo+.h,h,p);; 
\end{lstlisting}

\end{frame}




\begin{frame}[fragile]
\xc
 

Avec XCAS~:


\begin{lstlisting}
min_bis(f,xo,h,p):={
if(abs(h)<p)then{xo}
else{if(f(xo+h)>f(xo))
     then{min_bis(f,xo,-0.1*h,p)}
     else{min_bis(f,xo+h,h,p)}
}
}:;
\end{lstlisting}

\end{frame}






\section{Dichotomie}


\begin{frame}


Pour résoudre une équation  du type $f(x)=0$, on recherche graphiquement
un intervalle $[a,b]$ où la fonction semble changer de signe.

\pause

On note ensuite $m$ le milieu du segment $[a,b]$. On évalue le signe de $f(m)$.


\pause

Si c'est  le même  que celui  de $f(a)$ on  remplace $a$  par $m$  et on
recommence.  Sinon, c'est $b$  qu'on remplace  et on  recommence jusqu'à
obtenir la précision voulue.


\end{frame}




\subsection{Version récursive}



\begin{frame}[fragile]
             \caml
              

En CAML~:

\caml

\begin{lstlisting}
# let rec dicho_rec(f,a,b,eps)=
    if abs_float(b-.a)<eps then 0.5*.(b+.a)
    else if f(a)*.f(0.5*.(b+.a))>0. then dicho_rec(f,0.5*.(b+.a),b,eps)
         else  dicho_rec(f,a,0.5*.(b+.a),eps);;
\end{lstlisting}


\pause

ce qui donne~:


\begin{lstlisting}
# dicho_rec( (fun x->(x*.x-.2.)),1.,2.,0.00001);;
- : float = 1.41421127319335938
\end{lstlisting}

\end{frame}







\begin{frame}[fragile]
\xc
 

En XCAS~:

\begin{lstlisting}
dicho_rec(f,a,b,eps):={
if(evalf(b-a)<eps){return(0.5*(b+a))};
if(f(a)*f(0.5*(b+a))>0){return(dicho(f,0.5*(b+a),b,eps))}
                   else{return(dicho(f,a,0.5*(b+a),eps))}
}:;
\end{lstlisting}

\end{frame}






\subsection{Version impérative}




\begin{frame}[fragile]
              

\begin{algorithm}[H]
\Entree{une fonction f, les bornes a et b, une précision p}
\Ini{aa\aff a, bb\aff b}
\Deb{
\Tq{bb-aa>p}{
\eSi{signe  de  f((aa+bb)/2) est  le  même  que  celui de  f(bb)}{bb\aff
  (aa+bb)/2}{aa\aff (aa+bb)/2}
}
\Retour{(aa+bb)/2}
 } 
\end{algorithm}
\end{frame}






\begin{frame}
  
Avec XCAS, il faut juste ne pas oublier de régler quelques problèmes de précision~:

\end{frame}


\begin{frame}[fragile]
\xc
 

\begin{lstlisting}
dicho(F,p,a,b):={
local aa,bb,k,f;
aa:=a;
bb:=b;
epsilon:=1e-100; // on règle le "zéro" de XCAS à une valeur suffisamment petite
f:=unapply(F,x);// on transforme l'expression f en fonction
k:=0; // on place un compteur
 tantque evalf(bb-aa,p)>10^(-p) faire
    si sign(evalf(f((bb+aa)/2),p))==sign(evalf(f(bb),p))
      alors bb:=evalf((aa+bb)/2,p);
      sinon aa:=evalf((aa+bb)/2,p);
      k:=k+1; // un tour de plus au compteur
    fsi;
 ftantque;
return evalf((bb+aa)/2,p)+" est la solution trouvée après " +k+ " itérations";
}:;

\end{lstlisting}

\end{frame}




\section{Méthode de \textsc{Newton}}


\begin{frame}
  

Les  prérequis sont  plus nombreux~!  Il  faut avoir  étudié les  suites
définies   par   une   relation   du   type   $u_{n+1}=f(u_n)$   et   la
dérivation... et ne pas être trop perdu en Analyse...

Un exemple de TP possible en terminale S est présenté dans le poly.

\end{frame}



\begin{frame}

\begin{center}
  \includegraphics[width=.8\linewidth]{newtonb.1}
\end{center}

\end{frame}




\subsection{Algorithme récursif}



\begin{frame}[fragile]
\xc
 

En   XCAS~:~on    notera   que   \verb+function_diff(f)+    renvoie   la
\emph{fonction}  dérivée donc  \verb+function_diff(f)(x0)+  désigne 
le \emph{nombre} dérivé de $f$ en $x_0$.

\pause


\begin{lstlisting}
newton_rec(f,x0,eps):={
if(evalf(abs(f(x0)/function_diff(f)(x0)))<eps){evalf(x0)}
else{newton_rec(f,evalf(x0-f(x0)/function_diff(f)(x0)),eps)}
}:;
\end{lstlisting}


\end{frame}




\begin{frame}[fragile]
\xc
 

Alors, après avoir fixé par exemple la précision à 100~:

\begin{lstlisting}
DIGITS:=100:;
newton_rec(x->x^2-2,1.0,evalf(10^(-99)))
\end{lstlisting}

\pause

On obtient immédiatement~:

\verb+1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415728+

\end{frame}





\begin{frame}[fragile]
              

En  OCAML~:  il y  a  un  petit plus  car  il  faut  définir une  dérivée
approchée.

\caml

\begin{lstlisting}
# let der(f,x,dx)=(f(x+.dx)-.f(x))/.dx;;
\end{lstlisting}


\end{frame}




\begin{frame}[fragile]
             \caml
              

Maintenant la partie Newton~:

\begin{lstlisting}
# let rec newton_rec(f,xo,dx,eps)=
     if abs_float(f(xo)/.der(f,xo,dx))<eps then xo
     else newton_rec(f,xo-.f(xo)/.der(f,xo,dx),dx,eps);;
\end{lstlisting}

\end{frame}

\begin{frame}[fragile]
             \caml
              
\begin{lstlisting}
# let k(x)=x*.x-.2.;;

# newton_rec(k,1.,0.0001,0.000000001);;
- : float = 1.41421356245305962
\end{lstlisting}
\end{frame}




\subsection{Algorithme impératif}


\begin{frame}
Ça se complique un peu~:~évidemment,  car il faut faire de l'informatique
au lieu de se concentrer sur les mathématiques... :-)
\end{frame}



\begin{frame}[fragile]
              

\begin{algorithm}[H]
\Entree{
fonction $f$
 précision $p$
premier terme $a0$
nombre maximum d'itération \tcp{Pour éviter de \og planter\fg{}  si
  on tombe sur un cas pathologique}
}
\Ini{
$fp$\aff dérivée de $f$\;
compteur\aff 0 \tcp{le compteur d'itérations}
$un$\aff $u0-\frac{f(u0)}{fp(u0)}$

}
\Deb{
\Tq{$\left|\frac{f(xn)}{fp(xn)}\right|$   est   plus   grand  que   la
  précision $p$ et que $k<N$}{
\Si{$fp(un)=0$}{On sort  de la  boucle avant de  diviser par zéro  et on
  explique pourquoi}
$un$\aff $un-\frac{f(un)}{fp(un)}$
compteur\aff compteur+1
}
 }
\Retour{L'approximation et la valeur du compteur} 
\end{algorithm}

\end{frame}

\begin{frame}


Comparez ensuite avec les résultats trouvés avec la dichotomie.

Regardez également ce qui  se passe avec l'équation $(x-1)^4=0$~:~quelle
précaution   supplémentaire   faut-il   prendre~?   (La   preuve   n'est
évidemment pas envisageable au Lycée).
\end{frame}




\section{Méthode d'\textsc{Euler}}

\begin{frame}

Supposons qu'on connaisse  $f'(x)$ en fonction de $x$  et de $f(x)$ sous
la forme $f'(x)=u\bigl(f(x),x\bigr)$.

On utilise le fait que $f'(x)\approx \frac{f(x+h)-f(x)}{h}$. Alors

\[f(x+h)\approx h\cdot u\bigl(f(x),x\bigr)+f(x) \]

La traduction algorithmique est alors directe.
\end{frame}




\subsection{Version récursive}


\begin{frame}[fragile]
\xc
 

Pour la liste des coordonnées de points~:


\begin{lstlisting}
Euler(u,x,xmax,y,h,liste):={
 if(x>=xmax)
   then{liste}
   else{ Euler(u,x+h,xmax,y+u(y,x)*h,h,[op(liste),[x,y]])}
}:;
\end{lstlisting}


\end{frame}



\begin{frame}[fragile]
\xc
 

Puis pour le tracé~:

\begin{lstlisting}
trace_euler(u,xo,xmax,yo,h):={
polygonplot([Euler(u,xo,xmax,yo,h,[])])
}:;
\end{lstlisting}


\end{frame}




\begin{frame}[fragile]
\xc
 

Alors, pour  résoudre graphiquement $y'=-y$ avec  $y(0)=1$, sur $[-2;2]$
avec un pas de $0,01$ on entre~:

\begin{lstlisting}
trace_euler((y,x)->-y,-2,2,1,0.01)
\end{lstlisting}

\end{frame}



\begin{frame}
  


\begin{figure}
\begin{center}
  \includegraphics[width=0.8\textwidth]{euler}
\end{center}
\end{figure}
\end{frame}


\subsection{Version impérative}




\begin{frame}
  
On effectue une division régulière en découpant notre intervalle d'étude
$[a;b]$ en $N$ points.
\end{frame}

\begin{frame}[fragile]
\xc
 

\begin{lstlisting}
EulerImp(u,N,a,b,yo):={
S:=NULL; 
X:=a;  
Y:=yo;  
h:=(b-a)/N  
pour k de 0 jusque N pas 1 faire
X:=a+k*h; 
Y:=Y+u(Y,X)*h; 
S:=S,[X,Y];  
fpour  
polygonplot([S]); 
}:;

\end{lstlisting}

\end{frame}



\section{Intégration numérique}

\subsection{Méthode des rectangles}



\subsubsection{Version récursive}


\begin{frame}[fragile]
             \caml
              

\begin{lstlisting}
# let rec integ(f,a,b,dx)=
      if a>b then 0.
      else f(a)*.dx+.integ(f,a+.dx,b,dx);;
\end{lstlisting}

\end{frame}






\begin{frame}[fragile]
             \caml
              

Par exemple~:

\begin{lstlisting}
# let g(x)=x;;

# integ(g,0.,1.,0.0001);;
\end{lstlisting}



donne~:


\pause

\begin{lstlisting}
- : float = 0.500049999999960249
\end{lstlisting}

\pause


C'est-à-dire $\ds\int_0^1x \mathrm{d}\; x\approx 0.5$

\end{frame}





\subsubsection{Version impérative}



\begin{frame}[fragile]
\xc
 

\begin{lstlisting}
integ_rectangle(f,a,b,dx):={
local aa,I;
aa:=a;
I:=0;
 while(aa<b){
 I:=I+f(aa)*dx;
 aa:=aa+dx;
 }
return(I)
}:;
\end{lstlisting}

\end{frame}





\subsection{Méthode des trapèzes}




\subsubsection{Version récursive}



\begin{frame}[fragile]
             \caml
              

\begin{lstlisting}
# let rec integ_trap(f,a,b,dx)=
      if a>b then 0.
      else 0.5*.dx*.(f(a)+.f(a+.dx))+.integ_trap(f,a+.dx,b,dx);;
\end{lstlisting}

\pause

\begin{lstlisting}
# integ_trap(g,0.,1.,0.0001);;
- : float = 0.500100004999960213
\end{lstlisting}


\end{frame}




\subsubsection{Version impérative}


\begin{frame}[fragile]
\xc
 

\begin{lstlisting}
integ_trap(f,a,b,dx):={
local aa,I;
aa:=a;
I:=0;
 while(aa<b){
 I:=I+(f(aa)+f(aa+dx))*dx*0.5;
 aa:=aa+dx;
 }
return(I)
}:;
\end{lstlisting}

\end{frame}







\end{document}

%%% Local Variables: 
%%% TeX-master: t
%%% End: 
