Variable assigns value but wont plot
显示 更早的评论
clc, clear , close all
%Establish given conditions
dt= .001; %time interval (sec)
e=.05; %damping ratio 5%
H=30; %post height (m)
A=1.82; %cross sectional area (m^2)
S= 1.67; %Section Modulus (m^3)
m=10; %mass of water tank (Mg)
k=5; %Beam stiffness coefficient (MN/m)
timevec= 0:dt:3; % 3 sec time vector
a=.5; %alpha constant
B=.25; %beta constant
ui=0; %initial displacement
vi=0; %initial velocity
%Applied force
%F= [400,0,400,0,400,0];
%t= [0,.06,.15,.21,.30,.36];
wn= sqrt(k*10^3/m); %natural frequency
ccrit=2*m*wn; %critical damping
c=ccrit*e; %System damping coefficient
%Initial accel calculation
ai= 400/(m*10^3); %m/s^2
figure()
for i= timevec
if i>=0 && i<.06
Fi1=400;
elseif i>=.06 && i<.15
Fi1=0;
elseif i>=.15 && i<.21
Fi1=400;
elseif i>=.21 && i<.30
Fi1=0;
elseif i>=.30 && i<.36
Fi1=400;
elseif i>=.36
Fi1=0;
end
%displacement at ti+1
ui1term1= ( ( 1/(a*dt^2)*m + B/(a*dt)*c + k )^-1 ) ;
ui1term2= m * (ui/(a*dt^2) + vi/(a*dt) + ai*(1/(2*a) -1));
ui1term3= c * ( B*ui/(a*dt) + (B/a -1)*vi + (B/a -2)*(dt/2)*ai);
ui1= ui1term1 * (Fi1 +ui1term2 +ui1term3 ) ;
%acceleration at ti+1
ai1term1= 1/(a*dt^2)*(ui1-ui);
ai1term2= vi/(a*dt);
ai1term3= ai*(1/(2*a) - 1);
ai1= ai1term1 - ai1term2 - ai1term3;
%velocity at ti+1
vi1= vi +(1-B)*dt*ai + B*dt*ai1;
plot(i,ui,'b')
hold on
ui=ui1;
ai=ai1;
vi=vi1;
end
So the problem is my code will assign values while to ui (displacement variable) but it wont plot the graph representing the displacement curve of the system. Any help please?
采纳的回答
更多回答(1 个)
Steven Lord
2019-11-21
0 个投票
If you want to add points to your line one by one as your loop iterates you could create an animatedline before entering your for loop and addpoints to it inside the loop.
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!