How to Calculate Area Between a Curve and Two Lines?

1 次查看(过去 30 天)
Hi Everyone,
I am trying to calculate area (yellow area in attached figure) between curve and vertical and horizental axies lines. the code is provided as below. Could anyone help me?
Thank you in advance for you help.
Thank you,
clear all
clc
close all
%%
m=60;L=1;J=60;g=9.81;beta2=411.67;
KPb=2.15;KDb=0.75;
Time_Delay_Brain=0.19;
Time_Delay_Exo=0.05;
%%
for j=1:length(Time_Delay_Brain)
for jj=1:length(Time_Delay_Exo)
if Time_Delay_Exo(jj) ==0.05
n=11;
else
n=8;
end
%%
tau1=Time_Delay_Brain(j);tau2=Time_Delay_Exo(jj);
W = linspace(0, n*pi, 1000);omega=W;
Kpe=@(omega)J.*cos(omega.*tau2).*omega.^2 - KDb.*beta2.*omega.*sin(omega.*tau1 - omega.*tau2) + L.*cos(omega.*tau2).*g.*m - KPb.*beta2.*cos(omega.*tau1 - omega.*tau2);
Kde=@(omega)(omega.^2.*J.*sin(omega.*tau2) - KDb.*beta2.*omega.*cos(omega.*tau1 - omega.*tau2) + m.*g.*L.*sin(omega.*tau2) + KPb.*beta2.*sin(omega.*tau1 - omega.*tau2))./omega;
%%
D_Curve_PD_KPe=Kpe(omega);
D_Curve_PD_KDe=Kde(omega);
%%
plot(D_Curve_PD_KPe,D_Curve_PD_KDe,'color',[2*Time_Delay_Exo(jj) 2*Time_Delay_Brain(j) Time_Delay_Exo(jj) *Time_Delay_Brain(j)],'LineWidth', 0.2)
axis([0,18000,0,2500]);
hold on
end
hold on
end
plot([0 18000],[0 0],'color',[1 0 0],'LineWidth', 3)
plot([0 0],[0 2500],'color',[1 0 0],'LineWidth', 3)

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-8-15
编辑:Scott MacKenzie 2021-8-15
At the end of your code, add...
x = D_Curve_PD_KPe;
y = D_Curve_PD_KDe;
cropLogical = x > 0;
x = x(cropLogical);
y = y(cropLogical);
% define vertices of polyshape and plot
x = [0 0 x x(end) 0];
y = [0 y(1) y 0 0];
ps = polyshape(x,y);
plot(ps, 'facecolor', 'y');
% compute and output area
a1 = polyarea(x,y);
fprintf('area = %.2f\n', a1);
Output:
area = 16482962.65
  3 个评论
Scott MacKenzie
Scott MacKenzie 2021-8-16
It sounds like you want the area in region I -- with 0,0 at the bottom-left. In this case, modify my code by changing
cropLogical = x > 0 ;
to
cropLogical = x > 0 & y > 0 ;

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by