Effacer les filtres
Effacer les filtres

Finding solution of integral by using areas under the function curve

1 vue (au cours des 30 derniers jours)
Yusuf
Yusuf le 18 Jan 2014
Réponse apportée : Amit le 18 Jan 2014
Hello,
i want to solve an integral which has intial value=a and last value is b by using the area of under the fuction curve. y=f(x)=x^2-10x+25 M=number of area that i want to divide under the curve k=(b-a)/M ( the value represent the increase of x ) X1=0 X2=X1+k Y1=f(X1) Y2=f(X1+k) so the area is( Y1+Y2)/2*(X2-X1) and but i want to write this in for loop and divide many piece of the area of under the curve and sum up the to find integral solution it is help you to imagine it http://tr.wikipedia.org/wiki/Dosya:Riemann.gif please i need your help
  3 commentaires
Roger Stafford
Roger Stafford le 18 Jan 2014
Apparently Yusuf wants to write code using the trapezoidal rule as in 'trapz' for approximating the given integral. However, the referenced Wikipedia article is using f((x1+x2)/2)*(x2-x1) instead of (f(x1)+f(x2))/2*(x2-x1) as an approximation for the integral from x1 to x2. Either method would give an approximation. I think we need to see some attempt at coding before giving any specific advice.
Amit
Amit le 18 Jan 2014
what are a and b? x_initial and x_final?

Connectez-vous pour commenter.

Réponses (1)

Amit
Amit le 18 Jan 2014
Lets say you want to integrate from x = a to x = b (I am taking a = 0 and b = 2), you can change accordingly for your system.
a = 0;
b = 2;
M = 100;
x = linspace(a,b,M+1); % Cause there will be M+1 points if you're dividing into M areas
y = x.^2 -10*x+25;
Area = sum(((y(2:M+1)+y(1:M)).*(x(2:M+1)-x(1:M))/2));
Btw., trapezoid rule is (x2-x1)*(y2+y1)/2 and not (y2+y1)/2*(x2-x1)

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by