필터 지우기
필터 지우기

Calculate the area between two curves

조회 수: 4 (최근 30일)
maria
maria 2014년 4월 10일
편집: Alberto 2014년 4월 11일
i need help! i am new at using the Matlab and Scilab softwares and i need to calculate the area between the curves y=f(x) and y=g(x) in the interval [a,b] with a = 3, b = 6,
f (x)=sin(3 x+1) and g(x)=(e∣x∣/2−2−1)
by means of the composite trapezoidal rule with 73 trapezoids,Recall that the area between f and g in [a,b] is
b a ∫ ∣f(x)−g(x)∣dx
The approximate value of the area has to be displayed at the end, and the script must contain all the code to obtain the result.
how do i even begin with this? any help is much appreciated. thanks

채택된 답변

Alberto
Alberto 2014년 4월 11일
f =@(x) sin(3.*x+1) ;
g=@(x) exp(abs(x)/2 -2)-1;
a=3; b=6;
x=linspace(a,b,73); S=0;
for k=1:length(x)-1
S=S+abs( f(x(k+1)) - g(x(k+1)) - f(x(k)) +g(x(k)) )/2;
end
S
  댓글 수: 2
maria
maria 2014년 4월 11일
thank you! thank you!!! i have tried this out on my pc.. and i get S = 0 for all 72 columns. is this it for that question or is there another step afterwards and i have uploaded an image that came with the question. please take a look at it.. i know i am hopeless but bear with me for a bit longer..
Alberto
Alberto 2014년 4월 11일
편집: Alberto 2014년 4월 11일
Actually S is not a vector; S has the cumulative sum of trapezoids. The value I get is:
S = 2.7752
and has no columns. Maybe there are some conflicts with other parts.
Show me your whole code so I can check

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Robust Control Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by