How to Calculate Area Between a Curve and Two Lines?

1 visualización (últimos 30 días)
N/A
N/A el 15 de Ag. de 2021
Comentada: N/A el 16 de Ag. de 2021
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)

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 15 de Ag. de 2021
Editada: Scott MacKenzie el 15 de Ag. de 2021
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 comentarios
Scott MacKenzie
Scott MacKenzie el 16 de Ag. de 2021
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 ;
N/A
N/A el 16 de Ag. de 2021
Thank you so much. It does work! You saved me

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by