when and how to use dot multiplication
42 ビュー (過去 30 日間)
古いコメントを表示
ok, for my first practice homeowrk, since i have no idea what i am doing in matlab, i was asked to plot the response of a RLC equation that is in the time domain. I got the correct answer, but im not sure what the syntax is doing and if it is needed.
q0=10;R=60;L=9;C=0.0005;
t=linspace(0,0.8)
q=q0*exp(-R*t/(2*L)).*cos(sqrt(1/(L*C)-(R/(2*L))^2)*t);
plot(t,q)
in the equation q, there is the .* operation. Is that even needed if a matrix was not even used? im confused as when to use .* vs *
i know if i had
a=[1 2 3]
b=[5 6 7]
a.*b
would return
5 12 21
but is .* needed in my above q equation?
thanks
0 件のコメント
採用された回答
Voss
2022 年 5 月 13 日
"but is .* needed in my above q equation?"
Yes.
t is a vector, and q0, R, L, and C are all scalars.
q0=10;R=60;L=9;C=0.0005; % scalars
t=linspace(0,0.8); % 1-by-100 vector
Consider the expressions to the left and to the right of the .*, which both include t and some scalars:
q0*exp(-R*t/(2*L)) % vector the size of t
cos(sqrt(1/(L*C)-(R/(2*L))^2)*t) % vector the size of t
They are both vectors the size of t, so when you multiply those two vectors, you want to do it element-wise, which is what .* does
q=q0*exp(-R*t/(2*L)).*cos(sqrt(1/(L*C)-(R/(2*L))^2)*t)
giving you another vector the size of t.
9 件のコメント
Matt J
2023 年 8 月 12 日
If so, you should Accept-click the answer, and likewise with other valid answers to your posted questions.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Parallel Computing Fundamentals についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!