Exercice 2
> | restart:Digits:=30:with(plots):with(plottools): |
> | fI:=t->4/(1+t^2):aI:=0:bI:=1:NI:=20: |
> | fJ:=t->exp(-t*t):aJ:=-10:bJ:=10:NJ:=20: |
> |
Question a)
> | Rectangle_g:=proc(f,a,b,N)
local i,S; S:=0; for i from 0 to N-1 do S:=S+f(a+i*(b-a)/N); od; S:=S*(b-a)/N; end: |
> |
> | Question b) |
Calcul approché de I avec 20 Rectangles où
> | I=Int(fI(t),t=aI..bI); |
> | I_(approché):=evalf(Rectangle_g(fI,aI,bI,NI)); |
> | erreur:=evalf(abs(I_(approché)-Pi)); |
> |
Calcul approché de J avec 20 Rectangles où
> | J=(Int(fJ(t),t=aJ..bJ))**2; |
> | J_(approché):=evalf((Rectangle_g(fJ,aJ,bJ,NJ))**2); |
> | erreur:=evalf(abs(J_(approché)-Pi)); |
> |
> | Question c) |
> | Points_Rg:=proc(f,a,b,N)
local i,S; S:=NULL; for i from 1 to N do S:=S,[i/N,Rectangle_g(f,a,b,i)]; od; [S]; end; |
> |
> | plot(Points_Rg(fI,aI,bI,50)); Tracé des points obtenus pour le calcul approché de I |
> | plot(Points_Rg(fJ,aJ,bJ,50)); Tracé des points obtenus pour le calcul approché de J |
> |
> | Question d) |
> | Suite_Rg:=proc(f,a,b,N)
local i,S,suite,delta; delta:=(b-a)/N;S:=NULL; for i from 0 to N-1 do S:=S,polygon([[a+i*delta,0],[a+(i+1)*delta,0],[a+(i+1)*delta,f(a+i*delta)],[a+i*delta,f(a+i*delta)]],color=red,thickness=2); od; S; end: |
> |
Tracé des rectangels correspondant à l'intégrale I
> | RgI:=Suite_Rg(fI,aI,bI,NI):GI:=plot(fI,aI..bI,color=black,thickness=3): |
> | plots[display](RgI,GI); |
Tracé des rectangels correspondant à l'intégrale J
> | RgJ:=Suite_Rg(fJ,aJ,bJ,NJ):GJ:=plot(fJ,aJ..bJ,color=black,thickness=3): |
> | plots[display](RgJ,GJ); |
> |
Une petite animation
> |
> | Anim_Rg:=proc(t) plots[display](GI,Suite_Rg(fI,aI,bI,trunc(t))); end: |
> | animate(Anim_Rg,[t],t=1..NI, frames=50); |
> |
> |