How to calculate an area with obtained nodes?

6 views (last 30 days)
Hi Everyone,
I am going to calculate the area covered by nodes in the plot, but I do not know how! Could someone help me?
Thank you,
The code is copied as bellow:
clear all;clc;close all
%%
Mass=60;Lenght=1;g=10;Ja=60;alpha=(Mass*Lenght*g)/Ja;Zeta3=411.67/Ja;
Time_Delay=0.2;
N=7;
%%
s1=0;
s2=-Time_Delay;
[Phi_0_s,Phi_TD_s,Diff_Phi_TD_s]=Shape_Function(N,Time_Delay,s1,s2);
%%
[M,K]=M_K(N,Time_Delay);
%%
counter=[];
KP=0:0.1:3;
KD=0:0.1:3;
for ii=1:length(KP)
KP(ii)
for i=1:length(KD)
KP1=Zeta3*KP(ii);
KD1=Zeta3*KD(i)
L=Evaluation(KP1,KD1,alpha,Phi_0_s,Phi_TD_s,M,K);
Max_Real_EignValues=max(real(eig(L)));
if Max_Real_EignValues<0
plot(KP(ii),KD((i)),'r*','MarkerSize',5)
hold on
end
end
end
hold on
%% Below Lines are the functions related to top calculations
function [Phi_0_s,Phi_TD_s,Diff_Phi_TD_s]=Shape_Function(N,Time_Delay,s1,s2)
Phi_0_s(1)=1;
Phi_0_s(2)=1+2*s1/Time_Delay;
for k=3:N
Phi_0_s(k)=((2*k-3)*Phi_0_s(2)*Phi_0_s(k-1)-(k-2)*Phi_0_s(k-2))/(k-1);
end
Phi_0_s=Phi_0_s';
%%
Phi_TD_s(1)=1;
Phi_TD_s(2)=1+2*s2/Time_Delay;
for k=3:N
Phi_TD_s(k)=((2*k-3)*Phi_TD_s(2)*Phi_TD_s(k-1)-(k-2)*Phi_TD_s(k-2))/(k-1);
end
Phi_TD_s=Phi_TD_s';
%%
syms s
Phi_TTD_s=sym(zeros(1,N));
Phi_TTD_s(1)=1;
Phi_TTD_s(2)=1+2*s/Time_Delay;
for k=3:N
Phi_TTD_s(k)=((2*k-3)*Phi_TTD_s(2)*Phi_TTD_s(k-1)-(k-2)*Phi_TTD_s(k-2))/(k-1);
end
Diff_Phi_TD_s=diff(Phi_TTD_s,s);
Diff_Phi_TD_s=eval(subs(Diff_Phi_TD_s,s,-Time_Delay));
Diff_Phi_TD_s=double(Diff_Phi_TD_s);
Diff_Phi_TD_s=Diff_Phi_TD_s';
end
%%
function [A,B]=M_K(N,Time_Delay)
Delta=zeros(N,N);
A=zeros(N,N);
B=zeros(N,N);
for i=1:N
for j=1:N
if i==j
Delta(i,j)=1;
else
Delta(i,j)=0;
end
end
end
for i=1:N
for j=1:N
A(i,j)=(Time_Delay*Delta(i,j))/(2*i-1);
if i<j
if rem(i+j, 2) == 1
B(i,j)=2;
else
B(i,j)=0;
end
end
end
end
end
%%
function [L]=Evaluation(KP1,KD1,alpha,Phi_0_s,Phi_TD_s,M,K)
kp=KP1;
kd=KD1;
%% G1&G2
G1=alpha*Phi_0_s'-kp*Phi_TD_s';
G2=-kd*Phi_TD_s';
%% C3
C3=Phi_0_s'*inv(M)*Phi_0_s;
%% X Matrix
X1=(Phi_0_s*Phi_0_s')/C3;
X2=-((Phi_0_s*Phi_0_s'/M)*K)/C3;
X3=(Phi_0_s*G1)/C3;
X4=(Phi_0_s*G2-(Phi_0_s*Phi_0_s'/M)*K)/C3;
%% L Matrix
L1=K/M+X2/M;
L2=X1/M;
L3=X3/M;
L4=K/M+X4/M;
L=[L1 L2;L3 L4];
end
  3 Comments
N/A
N/A on 4 Aug 2021
Thank you for your response. Could you please use boundary function for my code for an example? I copied the code in the question part. I really need it. Thank you!

Sign in to comment.

Accepted Answer

darova
darova on 5 Aug 2021
An example of boundary function. polyarea is used to calculate area
r = 1;
x = linspace(-1,1,20);
y = sqrt(r^2 - x.^2);
x = [x; x];
y = [y; -y];
x = x(:);
y = y(:);
k = boundary(x(:),y(:));
plot(x,y,'.-r')
line(x(k),y(k))
legend('original order of points', 'boundary order')
polyarea(x(k),y(k))
ans = 3.1016
pi*r^2
ans = 3.1416

More Answers (0)

Categories

Find more on Mathematics and Optimization in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!