Trying to plot Eulers, but keep getting straight line

4 次查看(过去 30 天)
Whenever I try to plot, it tells me that the matrix dimensions must agree and I get a straight line. This is the second part of a question (the loop is from the first part and I know that works) so I'm confused as to where my syntax has gone wrong after the loop D:
m=5;
I=0.03;
%l=R for my own notation convention
l=0.3;
a=4.8;
g=9.81;
c=0.69;
%initial conditions tell us at n=1, t(1)=0, theta(1)=0, omega(1)=0
theta(1)=0;
omega(1)=0;
delta=0.001;
alpha(1)=(m*l*a*cos(theta(1))-c*omega(1)-m*l*g*sin(theta(1)))/(I+m*l^2);
Fy(1)=m.*g+c*omega(1)/l.*sin(theta(1)); %forces acting on point O in y direction
Fx(1)=m.*a-c*omega(1)/l.*cos(theta(1)); %forces acting on point O in x direction
% reusing the Euler's Method from 2a for the required vales
for n=1:10000
theta(n+1)=theta(n)+omega(n)*delta;
omega(n+1)=omega(n)+alpha(n)*delta;
alpha(n+1)=(m*l*a*cos(theta(n+1))-c*omega(n+1)-m*l*g*sin(theta(n+1)))/(I+m*l^2);
t(n+1)=n*delta;
Fy(n+1)=m.*g+c*omega(n+1)/l.*sin(theta(n+1));
Fx(n+1)=m.*a-c*omega(n+1)/l.*cos(theta(n+1));
acmi(n+1)=-a+(alpha(n+1)*l*cos(theta(n+1)))-((omega(n+1)^2)*l*sin(theta(n+1)));
end
%splitting into x and y components from free body diagram using Newton's
%2nd law in ijk vectors results in:
acmj(1)=alpha(1)*l.*sin(theta(1))+(omega(1)^2)*l*.cos(theta(1));
acmi(1:10001)=-a.+(alpha(n)*l*cos(theta(n)))-((omega(n)^2)*l*sin(theta(n)));
%F=ma
Rx=m*acmi;
plot(t,acmi)
axis tight

回答(1 个)

Matt J
Matt J 2019-12-7
编辑:Matt J 2019-12-7
You're getting a straight line because the right hand side of this line
acmi(1:10001)=-a+(alpha(n)*l*cos(theta(n)))-((omega(n)^2)*l*sin(theta(n)));
is just some scalar number. You have overwritten every acmi(n) calculated in the loop with this number and then plotted it. We have no way of knowing what you intended it to be instead.
  4 个评论
Matt J
Matt J 2019-12-7
编辑:Matt J 2019-12-7
No, that is unrelated to my advice. My advice was, don't overwrite the results of the loop with something trivial. Otherwise, the loop has no purpose.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by