Functions only plotting out to x=5
显示 更早的评论
I am attemping to plot 4 scenarios for oscillations, each scenario based on a different value of damping for the system. I think that I have generally accomplished that, but the plots only go out to x=5, and I think it would be helpful to show additional length in the x direction. What would be the best way to do so?
I thought perhaps I should enter "t = 0 : 0.1 : 10" just above the y= and fplot lines near the end of the loop, but received the error:
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
syms t C1 C2;
k=4;
m=2;
c_crit=2*sqrt(k*m);
c1=0.99*c_crit;
c2=0.25*c_crit;
c3=0.10*c_crit;
c4=0.02*c_crit;
F0=1;
omeganaught=sqrt(k/m);
omega=1;
for c=[c1 c2 c3 c4]
% calculate a and b and lambda for each iteration since we know c now
a=(m*(omeganaught^2-omega^2)/(m^2*(omeganaught^2-omega^2)^2+omega^2*c^2))*F0;
b=omega*c/(m^2*(omeganaught^2-omega^2)^2+omega^2*c^2)*F0;
lambda=c/(2*m);
% calculate phi and A now for each iteration now that a and b are known
A=sqrt(a^2+b^2);
phi=atan(b/a);
% now that we have phi, A, and lambda, can start solving for C1 and C2
% using IVs. Formulas for C1 and C2 derived on paper and typed in.
t=0;
C1=-A*cos(-phi);
C2=lambda*C1+A*sin(-phi);
clear t;
syms t;
y=exp(-lambda*t)*(C1*cos(omega*t)+C2*sin(omega*t)+A*cos(omega*t-phi));
fplot(t,y);
hold on;
end
axis([0 10 -0.2 0.2])
legend('0.99*c_c_r_i_t','0.25*c_c_r_i_t','0.10*c_c_r_i_t','0.02*c_c_r_i_t');
grid on
采纳的回答
更多回答(1 个)
fplot doesn't take t as the first argument as would have to be done for plot. Actually, I guess it can, but it's superfluous. Instead, use a second argument to fplot to indicate the desired plotting interval, as below.
syms t C1 C2;
k=4;
m=2;
c_crit=2*sqrt(k*m);
c1=0.99*c_crit;
c2=0.25*c_crit;
c3=0.10*c_crit;
c4=0.02*c_crit;
F0=1;
omeganaught=sqrt(k/m);
omega=1;
for c=[c1 c2 c3 c4]
% calculate a and b and lambda for each iteration since we know c now
a=(m*(omeganaught^2-omega^2)/(m^2*(omeganaught^2-omega^2)^2+omega^2*c^2))*F0;
b=omega*c/(m^2*(omeganaught^2-omega^2)^2+omega^2*c^2)*F0;
lambda=c/(2*m);
% calculate phi and A now for each iteration now that a and b are known
A=sqrt(a^2+b^2);
phi=atan(b/a);
% now that we have phi, A, and lambda, can start solving for C1 and C2
% using IVs. Formulas for C1 and C2 derived on paper and typed in.
t=0;
C1=-A*cos(-phi);
C2=lambda*C1+A*sin(-phi);
clear t;
syms t;
y=exp(-lambda*t)*(C1*cos(omega*t)+C2*sin(omega*t)+A*cos(omega*t-phi));
% fplot(t,y);
fplot(y,[0 25])
hold on;
end
%axis([0 10 -0.2 0.2])
legend('0.99*c_c_r_i_t','0.25*c_c_r_i_t','0.10*c_c_r_i_t','0.02*c_c_r_i_t');
grid on
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

