Riemann sum to find the area between two curves

3 ビュー (過去 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 Center および File ExchangeNumerical 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