How can I calculate the area between two curves?

5 ビュー (過去 30 日間)
Marko Boskovic
Marko Boskovic 2018 年 11 月 4 日
回答済み: madhan ravi 2018 年 11 月 4 日
I heave a problem, a need to calculate area between two curves, but one curve is too complicate (y1=(100./0.93).*(((x./19).^(10))./(1+(x./19).^(10))).*exp(-x./485), another curve is constant curve (y2=5). How I can calculate area between them?

採用された回答

Rik
Rik 2018 年 11 月 4 日
The polyarea function handles this just fine.
figure(1),clf(1)
x=0:1500;
y1=@(x)(100./0.93).*(((x./19).^(10))./(1+(x./19).^(10))).*exp(-x./485);
y2=@(x)5*ones(size(x));
plot(x,y1(x),x,y2(x))
Y=y1(x)-y2(x);
Y1=Y;
Y2=Y;Y2(Y2<0)=0;
Y3=abs(Y);
fprintf('A=%.0f (y2<y1 counting as negative)\n',polyarea(x,Y1))
fprintf('A=%.0f (y2<y1 not counting)\n',polyarea(x,Y2))
fprintf('A=%.0f (y2<y1 as well)\n',polyarea(x,Y3))

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 4 日
Answer taken from star strider:
x=0:10000;
y2=repmat(5,1,numel(x));
y1=(100./0.93).*(((x./19).^(10))./(1+(x./19).^(10))).*exp(-x./485);
x = 1:numel(y1); % Use The Appropriate Vector For The Most Accurate Results
hbar = min([y1; y2]); % Denoted By Horzontal Bars
vbar = max([y1; y2]) - hbar; % Denoted By Vertical Bars
Area = trapz(x,vbar) / (trapz(x,vbar) + trapz(x,hbar))

カテゴリ

Help Center および File ExchangeProbability Distributions and Hypothesis Tests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by