5 views (last 30 days)

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

Matt J
on 7 Dec 2019

Edited: Matt J
on 7 Dec 2019

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.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/495328-trying-to-plot-eulers-but-keep-getting-straight-line#comment_775555

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/495328-trying-to-plot-eulers-but-keep-getting-straight-line#comment_775555

Sign in to comment.