Info
此问题已关闭。 请重新打开它进行编辑或回答。
How can I reformat my loop to get result for given equations?
3 次查看(过去 30 天)
显示 更早的评论
The task is as follows:
Write Matlab program to simulate 2 seconds of engine motion starting at initial conditions of omega2=2*pi rad/s and TH2 = 0 degrees. Assume linear angular accel of alpha2 = 0.5*time (that's total elapsed time, NOT time increment dt).
Set time increment dt such that it always corresponds to a 2 degree increment in TH2 based on current omega2.
My attempt at coding:
w2=2*pi;
TH2=0;
t=2
a2=0.5*t;
L2=50;
L3=150;
for n=1:2:360
TH3(n)=acosd((L2*cosd(TH2))/L3)
d1(n)=((L2*sind(TH2))-(L3*sind(TH3)))
w3(n)=(L2*w2*sind(TH2))/L3*sind(TH3)
d2(n)=(L2*w2*cosd(TH2))-L3*w3*cosd(TH3)
a3(n)=((-L3*w3^2*cosd(TH3))+(L2*a2*sind(TH2)))+(L2*w2^2*cosd(TH2))/L3*sind(TH3)
d3(n)=(L2*a2*cosd(TH2))-(L2*w2^2*sind(TH2))-(L3*a3*cosd(TH3))+(L3*w3^2*sind(TH3))
end
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in DynamicsPistonProject (line 12)
d1(n)=((L2*sind(TH2))-(L3*sind(TH3)))
I understand that the error will not allow me to continue my loop as written. Is there a better way to write my program to get the output desired?
2 个评论
回答(1 个)
Kiran Prasad
2016-6-24
I think Torsten is right. If you run it afterwards you shouldn't get a dimension mismatch. Let us know if this still doesn't work. Best, Kiran
2 个评论
Kiran Prasad
2016-6-24
I haven't gone through your logic as of yet, but I would get rid of TH2(n) and keep it as TH2. Right now TH2 isn't a vector.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!