3D Plot for an integral function in a loop

조회 수: 9 (최근 30일)
Komal Rajana
Komal Rajana 2020년 9월 9일
댓글: Komal Rajana 2020년 9월 10일
Hello, I having some troubles plotting the function for the system below. Any assistance is greatly appreciated.
m1=5;
mtmd=0.25;
omg1=2*pi; %rad/s
beta=0.5
b=beta*m1
C1=0;
K1=(omg1^2)*m1;
Freqratio=linspace(0.1,1,10);
zitad=linspace(0.1,1,10);
[zitad,Freqratio]=meshgrid(zitad,Freqratio);
out=zeros(size(zitad))
for f=0.1:0.1:length(Freqratio)
for z=0.1:0.1:length(zitad)
kTMDI=Freqratio(f)^2*omg1^2*(mtmd+b)
cTMDI=2*zitad(z)*(mtmd+b)*Freqratio(f)*omg1
Ms=[mtmd 0;
0 m1;]
M=Ms + [b 0;0 0;];
K=[kTMDI -kTMDI;
-kTMDI kTMDI+K1;]
C=[cTMDI -cTMDI;
-cTMDI cTMDI+C1;]
n=size(M,1)-1;
I=eye(2*n+2);
C0=zeros(2*n+2,1)' % Is (2n+2) length Vector
C0(2)=1
ae1=zeros(n+1);
ae2=eye(n+1);
ae3=-(M\K); %A\B= inv(B)*A;
ae4=-(M\C);
ae5=zeros(n+1,1);
ae6=ones(n+1,1);
A=[ae1 ae2;ae3 ae4];
B=[ae5;M\(Ms*ae6)];
whiteNoiseFactor=1;
g2=@(w) abs(C0*(((1i*w).*I-A)\B))^2*whiteNoiseFactor;
out(f, z)=integral(g2,0,inf,'ArrayValued',true);
end
end
figure
surfc(Freqratio,zitad,out)

채택된 답변

VBBV
VBBV 2020년 9월 10일
편집: VBBV 2020년 9월 10일
Try now ... For loops cannot take decimal increments in matlab
%if true
% code
%end
m1=5;
mtmd=0.25;
omg1=2*pi; %rad/s
beta=0.5
b=beta*m1
C1=0;
K1=(omg1^2)*m1;
Freqratio=linspace(0.1,1,10);
zitad=linspace(0.1,1,10);
[zitad,Freqratio]=meshgrid(zitad,Freqratio);
out=zeros(size(zitad))
for f=1:length(Freqratio) % loops do not take decimal increments in matlab
for z=1:length(zitad)
kTMDI=Freqratio(f)^2*omg1^2*(mtmd+b)
cTMDI=2*zitad(z)*(mtmd+b)*Freqratio(f)*omg1
Ms=[mtmd 0;
0 m1;]
M=Ms + [b 0;0 0;];
K=[kTMDI -kTMDI;
-kTMDI kTMDI+K1;]
C=[cTMDI -cTMDI;
-cTMDI cTMDI+C1;]
n=size(M,1)-1;
I=eye(2*n+2);
C0=zeros(2*n+2,1)' % Is (2n+2) length Vector
C0(2)=1
ae1=zeros(n+1);
ae2=eye(n+1);
ae3=-(M\K); %A\B= inv(B)*A;
ae4=-(M\C);
ae5=zeros(n+1,1);
ae6=ones(n+1,1);
A=[ae1 ae2;ae3 ae4];
B=[ae5;M\(Ms*ae6)];
whiteNoiseFactor=1;
g2=@(w) abs(C0*(((1i*w).*I-A)\B))^2*whiteNoiseFactor;
out(f, z)=integral(g2,0,inf,'ArrayValued',true);
end
end
figure
surfc(Freqratio,zitad,out)% recommend to use mesh instead of surfc
  댓글 수: 3
VBBV
VBBV 2020년 9월 10일
편집: VBBV 2020년 9월 10일
Because you changed the limits of integration in [0 inf] to [-inf inf]
%if true
% code
%end
out(i,j)=integral(g2,-inf,inf,'ArrayValued',true)
You don't require a dot operator when using loop indices
%if true
% code
% end
kTMDI=F(i,j)^2*omg1^2.*(mtmd+b)...
Komal Rajana
Komal Rajana 2020년 9월 10일
thanks very much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by