Matrix to Scalar Problem

2 ビュー (過去 30 日間)
Nahuel
Nahuel 2023 年 9 月 6 日
コメント済み: MarKf 2023 年 9 月 6 日
Hi everyone,
I have a problem in the line 10, that it is ofcourse cause of the multiplication between a Matrix and a Scalar. But I do not find how to solve it.
  1. t=0:3:60;%seconds
  2. Pos0=0;%position
  3. Vel0=0;%velocity
  4. W=6.28;%frecuency
  5. e=2.71828;%Euler
  6. Damp_Coef=0;
  7. Wd=W*(1-Damp_Coef^2)^0.5;
  8. alfa=atan((Vel0+Pos0*Damp_Coef*W)/(Wd*Pos0));
  9. C=(Pos0^2+((Vel0+Pos0*Damp_Coef*W)^2)/Wd^0.5)^(0.5);
  10. x=C*e^(-Damp_Coef*W*t)*cos(Wd*t-alfa);
  11. figure
  12. plot(t,x)
  13. xlabel('time,s')
  14. ylabel('x(t)')
  15. legend('NANU')
  16. title('lets see')
  2 件のコメント
John D'Errico
John D'Errico 2023 年 9 月 6 日
編集済み: John D'Errico 2023 年 9 月 6 日
Please don't number those lines. That makes it impossible to copy your code. Why do you want to make it more difficult to get help? Just making the line in question bold faced as you did was certainly sufficient.
MarKf
MarKf 2023 年 9 月 6 日
fortuantely it is just a numbered list, so it is easy to copy actually... but yes interesting appoach, bold/underlined or even code %<-- issue here would have worked

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

回答 (3 件)

Les Beckham
Les Beckham 2023 年 9 月 6 日
t=0:3:60;%seconds
Pos0=1;%position <<< Pos0 can't be zero since you divide by Wd*Pos0 when calculating alfa
Vel0=0;%velocity
W=6.28;%frecuency
e=2.71828;%Euler
Damp_Coef=0.02; % <<< Damp_Coef can't be zero
Wd=W*(1-Damp_Coef^2)^0.5;
alfa=atan((Vel0+Pos0*Damp_Coef*W)/(Wd*Pos0));
C=(Pos0^2+((Vel0+Pos0*Damp_Coef*W)^2)/Wd^0.5)^(0.5);
x=C*exp(-Damp_Coef*W.*t).*cos(Wd.*t-alfa);
% ^ use exp instead of e^ and use element-wise multiplies: .* instead of *
figure
plot(t,x)
grid on
xlabel('time,s')
ylabel('x(t)')
legend('NANU')
title('lets see')

Torsten
Torsten 2023 年 9 月 6 日
x=C*exp(-Damp_Coef*W*t).*cos(Wd*t-alfa);

MarKf
MarKf 2023 年 9 月 6 日
Use a dot "." before an element-wise operation, that is also to multiply, divide, raise etc a scalar value to each of the element of a vector/matrix. Example below, tho not sure that's what you meant to do.
t=0:3:60;%seconds
Pos0=0;%position
Vel0=0;%velocity
W=6.28;%frecuency
e=2.71828;%Euler
Damp_Coef=0;
Wd=W*(1-Damp_Coef^2)^0.5;
alfa=atan((Vel0+Pos0*Damp_Coef*W)/(Wd*Pos0));
C=(Pos0^2+((Vel0+Pos0*Damp_Coef*W)^2)/Wd^0.5)^(0.5);
x=C*e.^(-Damp_Coef*W*t).*cos(Wd*t-alfa);
figure
plot(t,x)
xlabel('time,s')
ylabel('x(t)')
legend('NANU')
title('lets see')

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by