How to find area enclosed between two curves?
Show older comments
Lx = 150;
Ly = 150;
T0 =0;
T1 = pi/4;
T=3.175;
N=8;
W=N*T;
X0=Lx/2;
Y0=0;
W_nominal=W/2;
for a=1:2
r=rem(a,2);
if r==0
xp=0; xn=0; i=1;
while (xp>=0 && xp<=Lx/2)
XPaxisl(i)=xp+(i-1)*Lx/1200; xp=XPaxisl(i);
XNaxisl(i)=xn+(i-1)*(-Lx)/1200; xn=XNaxisl(i);
Th(i)=T0+2*((T1-T0)*(XPaxisl(i)))/Lx;
TH(i)= T0+2*((T0-T1)*(XNaxisl(i)))/Lx;
Wp(i)=W_nominal/cos(Th(i));
WP(i)=W_nominal/cos(TH(i));
ypl(i)=Wp(i)+(Lx/(2*(T0-T1))*((-log(cos(T0)))+log(cos(T0+((2*(T1-T0)*XPaxisl(i))/Lx)))));
ynl(i)=WP(i)+(Lx/(2*(T1-T0))*((-log(cos(T0)))+log(cos(T0+((2*(T0-T1)*XNaxisl(i))/Lx)))));
i=i+1;
end
plot(XPaxisl,ypl, '-g')
hold on
plot(XNaxisl,ynl, '-g')
hold on
end
%% shifting
r=rem(a,2);
if r==0
xp=0; xn=0; i=1; y=0; yn=0;
while (xp>=0 && xp<=Lx/2) && (y<=Ly/2)
XPaxiss1(i)=xp+(i-1)*Lx/1200; xp=XPaxiss1(i);
yps1(i) =(a*W_nominal)+Lx/(2*(T0-T1))*((-log(cos(T0)))+log(cos(T0+((2*(T1-T0)*XPaxiss1(i))/Lx))));
i=i+1;
end
else
xp=0; xn=0; i=1; y=0; yn=0;
while (xp>=0 && xp<=Lx/2) && (y<=Ly/2)
XPaxiss1(i)=xp+(i-1)*Lx/1200; xp=XPaxiss1(i);
XNaxiss1(i)=xn+(i-1)*(-Lx)/1200; xn=XNaxiss1(i);
yps1(i) =(a*W_nominal)+Lx/(2*(T0-T1))*((-log(cos(T0)))+log(cos(T0+((2*(T1-T0)*XPaxiss1(i))/Lx))));
yns1(i)= (a*W_nominal)+Lx/(2*(T1-T0))*((-log(cos(T0)))+log(cos(T0+((2*(T0-T1)*XNaxiss1(i))/Lx))));
i=i+1;
end
plot(XPaxiss1,yps1, '-r')
hold on
plot(XNaxiss1,yns1, '-r')
xlim([-Lx/2 Lx/2])
ylim([-Ly/2 Ly/2])
end
end
I want to claculate the area between red and green curves using trapz but im not getting the exact result and it is showing error while calculating.can anyone tell how can i calculate area? I attached code for reference.

Accepted Answer
More Answers (1)
i don't think the code you include in your question content related to what you want.
you have to vector, which are values of your curves at your grid points x.
here's an example for doing this task:
x = 0:0.1:20;
y1 = exp(x/2);
y2 = (x).^3;
dY = abs(y1-y2);
plot(x,y1,'Color','r','LineWidth',2);
hold on; grid on;
plot(x,y2,'Color','g','LineWidth',2);
plot(x,dY,'Color','b','LineWidth',2);
legend('y1 = exp(x/2)','y2= x^3','|y1-y2|','Location','best');
Diff = trapz(x,dY);
disp(['Area between 2 Curves :' num2str(Diff)])
1 Comment
Prakash Chettri
on 22 Feb 2022
Categories
Find more on App Building in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!