La reponse est simple (il suffit de chercher avec google) mais je crois que tu doit etudier un peu avant.
Code:
function int = simpcomp(a,b,m,fun)
%
% Formule de Cavalieri-Simpson composite
% (si on pose m=1 on a la formule simple)
%
% int = simpcomp(a,b,m,fun)
%
h=(b-a)/m;
x=[a:h/2:b];
dim = max(size(x));
y=eval(fun);
if size(y)==1,
y=diag(ones(dim))*y;
end
int=(h/6)*(y(1)+2*sum(y(3:2:2*m-1))+4*sum(y(2:2:2*m))+y(2*m+1));
Quand tu a compris ça tu peux essayer avec les autres formules d'interation.
Gloria
PS Pardon pour mes fautes mais je suis italienne :o
08/06/2006, 05h11
#33
gregoory
Date d'inscription
juin 2006
Âge
36
Messages
27
Re : Besoin d'aide en MATLAB
MERCI beaucoup gloria !
15/01/2010, 19h05
#34
bma.dz1
Date d'inscription
décembre 2009
Messages
2
Re : Besoin d'aide en MATLAB
Salut a tous
je pense que cette méthode ne contient aucune boucle
essaye ce script
Code:
a=input('Donnez la valeur A: ');
b=input('Donnez la valeur B: ');
P=input('Donnez la fonction comme [A B C]pour ax^2+bx+c: ');
f=inline(P);
S=((b-a)/6)*(polyval(P,a)+4*polyval(P,(a+b)/2)+polyval(P,b));
tu peut voir aussi la fonction suivante
Code:
function I = simprule(f_str, a, b, n)
%SIMPRULE Simpson's rule integration.
% I = SIMPRULE(F_STR, A, B, N) returns the Simpson's rule approximation
% for the integral of f(x) from x=A to x=B, using N subintervals, where
% F_STR is the string representation of f.
% An error is generated if N is not a positive, even integer.
I=0;
g = inline(f_str);
h = (b-a)/n;
if((n > 0) && (rem(n,2) == 0))
I = I + g(a);
for ii = (a+h):2*h:(b-h)
I = I + 4*g(ii);
end
for kk = (a+2*h):2*h:(b-2*h)
I = I + 2*g(kk);
end
I = I + g(b);
I = I*h/3;
else
disp('Incorrect Value for N')
end