I havent had to use matlab before. When i type out the code I was given it won't run because of an invalid expression. i can't figure out my mistep
close all
clear all
t=0;
theta0=pi()/3;
L=.5;
lam=6;
for n=1:161
t(n+1) =t(n)+.02;
theta(n)=theta0*sin(lam*t(n));
omega(n)=lam*theta0*cos(lam*t(n));
alpha(n)=-lam^2*theta(n);
xA(n)=t(n);
yA(n)=t(n)^(3)/18;
xB(n)=xA(n)+L*sin(theta(n));
yB(n)=yA(n)-L*cos(theta(n));
uA(n)=1;
vA(n)=t(n)^(2)/6;
uB(n)=uA(n)+L*omega(n)*cos(theta(n));
vB(n)=vA(n)+L*omega(n)*sin(theta(n));
axA(n)=0;
ayA(n)=t(n)/3;
axB(n)=L*alpha(n)*cos(theta(n))-L*omega(n)^2*sin(theta(n));
ayB(n)=ayA(n)+L*alpha(n)*sin(theta(n))+L*omega(n)^2*cos(theta(n));
end;
for n=1:161
line([xA(n) xB(n)]),[yA(n) yB(n)]);
end

 採用された回答

madhan ravi
madhan ravi 2018 年 11 月 3 日
編集済み: Stephen23 2018 年 11 月 3 日

0 投票

t=0;
theta0=pi/3; %error was NOT here
L=.5;
lam=6;
for n=1:161
t(n+1) =t(n)+.02; theta(n)=theta0*sin(lam*t(n));
omega(n)=lam*theta0*cos(lam*t(n)); alpha(n)=-lam^2*theta(n);
xA(n)=t(n);
yA(n)=t(n)^(3)/18;
xB(n)=xA(n)+L*sin(theta(n));
yB(n)=yA(n)-L*cos(theta(n));
uA(n)=1;
vA(n)=t(n)^(2)/6;
uB(n)=uA(n)+L*omega(n)*cos(theta(n));
vB(n)=vA(n)+L*omega(n)*sin(theta(n));
axA(n)=0;
ayA(n)=t(n)/3;
axB(n)=L*alpha(n)*cos(theta(n))-L*omega(n)^2*sin(theta(n));
ayB(n)=ayA(n)+L*alpha(n)*sin(theta(n))+L*omega(n)^2*cos(theta(n));
end;
line(xA, xB,'r') %error was here
hold on
line(yA,yB','g') %error was here

5 件のコメント

Maria Shehadeh
Maria Shehadeh 2018 年 11 月 3 日
It was the pi/3 in the end. thank you!
madhan ravi
madhan ravi 2018 年 11 月 3 日
Anytime :)
Walter Roberson
Walter Roberson 2018 年 11 月 3 日
No, pi is a function and using pi() /3 is legal.
The problem is that
line([xA(n) xB(n)]),[yA(n) yB(n)]);
has an extra ) after the first]
madhan ravi
madhan ravi 2018 年 11 月 3 日
Ah thank you sir Walter didn’t notice it because the question was edited at the beginning until you did
Maria Shehadeh
Maria Shehadeh 2018 年 11 月 3 日
Just caught that didn't realize I retyped it properly in the end. Thanks!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLanguage Fundamentals についてさらに検索

質問済み:

2018 年 11 月 3 日

編集済み:

2018 年 11 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by