필터 지우기
필터 지우기

when and how to use dot multiplication

조회 수: 42 (최근 30일)
Matt Thomas
Matt Thomas 2022년 5월 13일
댓글: John D'Errico 2023년 8월 12일
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

채택된 답변

Voss
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
ans = 1×100
10.0000 9.7342 9.4755 9.2237 8.9786 8.7400 8.5077 8.2816 8.0615 7.8472 7.6387 7.4357 7.2381 7.0457 6.8584 6.6762 6.4987 6.3260 6.1579 5.9942 5.8349 5.6799 5.5289 5.3820 5.2389 5.0997 4.9642 4.8323 4.7038 4.5788
cos(sqrt(1/(L*C)-(R/(2*L))^2)*t) % vector the size of t
ans = 1×100
1.0000 0.9931 0.9726 0.9386 0.8917 0.8326 0.7620 0.6808 0.5904 0.4917 0.3864 0.2757 0.1612 0.0444 -0.0729 -0.1892 -0.3029 -0.4125 -0.5164 -0.6131 -0.7015 -0.7801 -0.8480 -0.9043 -0.9481 -0.9788 -0.9961 -0.9996 -0.9894 -0.9655
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)
q = 1×100
10.0000 9.6672 9.2155 8.6574 8.0065 7.2767 6.4825 5.6385 4.7592 3.8588 2.9513 2.0497 1.1664 0.3131 -0.5000 -1.2633 -1.9688 -2.6095 -3.1798 -3.6753 -4.0929 -4.4309 -4.6887 -4.8668 -4.9668 -4.9916 -4.9446 -4.8303 -4.6538 -4.4210
giving you another vector the size of t.
  댓글 수: 9
Matt J
Matt J 2023년 8월 12일
If so, you should Accept-click the answer, and likewise with other valid answers to your posted questions.
John D'Errico
John D'Errico 2023년 8월 12일
Now over a year old, and unaccepted. I did so myself.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by