作者willsnowman (Snowman)
看板MATLAB
标题[讨论] Vectors的长度问题(新手)
时间Mon Jan 28 11:51:38 2013
小弟今天第一次写Matlab
基础不太好
想请教一下
目前我遇到的问题是
Vectors must be the same lengths.
改了好久还是有同样错误
因此想请教一下板上的高手这程式的问题点在哪?
谢谢!
程式码如下:
-----------------------stast form here-------------------------
time = 0; % s
dt = 0.001;
M1 = 2; % kg
B1 = 0.3; % N-s/m
K1 = 10; % N/m
M2 = 1; % kg
B2 = 0.7; % N-s/m
K2 = 5; % N/m
count = 2;
time(1) = 0;
f(1) = 0;
xdd1(1) = 0;
xd1(1) = 0;
x1(1) = 0;
xdd2(1) = 0;
xd2(1) = 0;
x2(1) = 1;
while time < 10
xdd2(count) = (-K2*(x2(count-1) - x1(count-1)) - B2*(xd2(count-1) - xd1(count-1)) + f(count-1))/M2;
xdd1(count) = (-K1*x1(count-1) - B1*xd1(count-1) + K2*(x2(count-1) - x1(count-1)) + B2*(xd2(count-1) - xd1(count-1)))/M1;
xd2(count) = xd2(count-1) + ((xdd2(count)+xdd2(count-1))/2)*dt;
xd1(count) = xd1(count-1) + ((xdd1(count)+xdd1(count-1))/2)*dt;
x2(count) = x2(count-1) + ((xd2(count)+xd2(count-1))/2)*dt;
x1(count) = x1(count-1) + ((xd1(count)+xd1(count-1))/2)*dt;
% no external force
f(count) = 0;
% oscillating external force
% f(count) = sin(time);
time(count) = time(count-1)+dt;
count = count+1;
end
plot(time,x1,'o')
plot(time,x2,':')
hold on
-----------------------end-------------------------
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 131.247.226.3
1F:推 JamesChen:看他 debug 是跟你讲哪一行 去检查阿 01/28 14:37
2F:→ JamesChen:就是向量长度不一 无法算 01/28 14:37
3F:→ willsnowman:请问怎麽去检视向量长度呢?我不太清楚要怎麽去查看.. 01/28 14:52
4F:→ ReiFu21:错误提示会说哪两个向量长度不一 在提示下分别输入那两个 01/28 15:08
5F:→ ReiFu21:向量按ENTER可以比较了 01/28 15:10