Finding solution of integral by using areas under the function curve

조회 수: 1 (최근 30일)
Yusuf
Yusuf 2014년 1월 18일
답변: Amit 2014년 1월 18일
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.
Amit
Amit 2014년 1월 18일
what are a and b? x_initial and x_final?

댓글을 달려면 로그인하십시오.

답변 (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