Riemann sum to find the area between two curves

조회 수: 1 (최근 30일)
UserCJ
UserCJ 2023년 3월 3일
댓글: UserCJ 2023년 3월 4일
I'm trying to find the Riemann sum of the area between two curves as shown in the diagram below. Xn is rescaled and a new data set is the difference between Xc and rescaled data. I need to take the Riemann sum over the region between these two (Xc and (Xn rescaled) data).
I have coded that as below, but I'm not sure how to take the Riemann sum of these data poionts.
phi = linespace(1,100,1)%array of 100 values
sol_n=xn.sol_all; %this is a 1500*100 data set
sol_c=xc.sol_all; %this is a 1500*100 data set
for i =1:length(phi)
Xn_new= (sol_n(:,i)).*((sol_c(end,i))./(sol_n(end,i))); %Rescaling Xn
Xc_new = sol_c(:,i);
Data = Xc_new- Xn_new;
end
Your help is greatly appreciated.

채택된 답변

Cameron
Cameron 2023년 3월 3일
x = 0:0.01:1; %some x data
s1 = x./(x+exp(1-7*x)); %some y data
s2 = x./(x+exp(1-10*x)); %some other y data
plot(x,s1,'b',...
x,s2,'r')
sumS1 = trapz(x,s1); %trapezoidal integration
sumS2 = trapz(x,s2); %trapezoidal integration
sumBetween = sumS2 - sumS1 %subtract the two for answer
sumBetween = 0.0742
  댓글 수: 1
UserCJ
UserCJ 2023년 3월 4일
@Cameron Thank you very much foryour help. That worked well!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by