Not sure how to fix my matrix dimension problem
1 回表示 (過去 30 日間)
古いコメントを表示
t=0:0.1:4
m=5;
k=1000;
zeta=[0, 0.1, 0.25, 0.5, 0.75, 0.9, 1];
xo=0.05;
vo=0;
w=sqrt(k/m)
wd=w*sqrt(1-zeta.^(2))
A=(sqrt((vo+zeta.*w.*xo).^(2)+(wd.*xo).^(2))).*(1./wd)
o=atan((xo*wd).*(1./(vo+zeta*w*xo)))
figure(1)
for i=1:length(zeta)
x=A.*exp(-w*zeta.*t).*sin(wd.*t+o);
plot(t,x)
hold on
end
0 件のコメント
回答 (2 件)
Adam Danz
2020 年 3 月 29 日
編集済み: Adam Danz
2020 年 3 月 29 日
t is a 1x41 vector; wd and zeta are both 1x7 vectors. You can't do pairwise multiplication with two arrays of different size.
Base on the line plot(t,x) I assume you are expecting t to have the same number of elements as x in which case t will also need to be a 1x7 vector.
Perhaps you're looking for
t = linspace(0,4,numel(zeta));
or
t = cumsum([0, 0.1 * ones(1,numel(zeta)-1)]);
But there's another problem/mystery: you're not using the i variable within your loop and the values for x will never change within the loop so you'll end up plotting the same line over and over again.
2 件のコメント
MaryD
2020 年 3 月 29 日
You are using for loop with variable i but you are not using i inside the loop. I'm not sure what you want to achive but maybe this will work
for i=1:length(zeta)
x=A(i).*exp(-w*zeta(i).*t).*sin(wd(i).*t+o(i));
figure(i)
plot(t,x)
hold on
end
3 件のコメント
Adam Danz
2020 年 3 月 29 日
編集済み: Adam Danz
2020 年 3 月 29 日
If you're plotting all of that on the same figure, move figure(1) and hold on outside of the loop (see my previous comment). Also, move title(), xlabel(), and ylabel() outside of the loop (before or after).
I also recommend you label the lines so you know which one is which.
for i = _____
x = ______
plot(t,x, 'DisplayName', num2str(i))
end
legend()
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!