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)
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!