Finding solution of integral by using areas under the function curve

1 次查看(过去 30 天)
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 个评论
Roger Stafford
Roger Stafford 2014-1-18
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.

请先登录,再进行评论。

回答(1 个)

Amit
Amit 2014-1-18
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)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by