Riemann sum to find the area between two curves

3 次查看(过去 30 天)
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

更多回答(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