Trying to plot Eulers, but keep getting straight line

4 ビュー (過去 30 日間)
Elizabeth Ng
Elizabeth Ng 2019 年 12 月 7 日
コメント済み: Elizabeth Ng 2019 年 12 月 7 日
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 件のコメント
darova
darova 2019 年 12 月 7 日
Can you attach your initial equations/formulas?

サインインしてコメントする。

回答 (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.
Elizabeth Ng
Elizabeth Ng 2019 年 12 月 7 日
Alright, thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by