[討論] Vectors的長度問題(新手)

看板MATLAB作者 (Snowman)時間13年前 (2013/01/28 11:51), 編輯推噓1(104)
留言5則, 3人參與, 最新討論串1/1
小弟今天第一次寫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

01/28 14:37, , 1F
看他 debug 是跟你講哪一行 去檢查阿
01/28 14:37, 1F

01/28 14:37, , 2F
就是向量長度不一 無法算
01/28 14:37, 2F

01/28 14:52, , 3F
請問怎麼去檢視向量長度呢?我不太清楚要怎麼去查看..
01/28 14:52, 3F

01/28 15:08, , 4F
錯誤提示會說哪兩個向量長度不一 在提示下分別輸入那兩個
01/28 15:08, 4F

01/28 15:10, , 5F
向量按ENTER可以比較了
01/28 15:10, 5F
文章代碼(AID): #1H1VNDvh (MATLAB)
文章代碼(AID): #1H1VNDvh (MATLAB)