Riemann sum to find the area between two curves

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Cameron
Cameron il 3 Mar 2023
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

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by