Hi all,
I am working with phasor responses in circuits, and in my textbook (Analysis and Design of Linear Circuits: 8th Edition by Thomas, Rosa, and Toussaint), I am given this code that takese two phasor values and displays it in its polar form:
% phasors.m %
% Source: TRT p.386
% Create the phasor values
V1 = 10*exp(-j*45*pi/180)
V2 = 5*exp(j*30*pi/180)
% Form the sum
V = V1 + V2
% Computes the polar form
MagV = abs(V);
PhaseV = angle(V);
PhaseVDeg = 180*PhaseV/pi;
% Display results
disp(['V=',num2str(MagV,'%3.4g'),...
exp(',num2str(PhaseVDeg,'%3.4g'),'j)'])
However, it doesn't run, and I'm not sure how to fix it. It should display as such:
V1 =
7.0711 - 7.0711i
V2 =
4.3301 + 2.5000i
V =
11.4012 - 4.5711i
V = 12.28 exp(-21.85j)
But the problem is that, as seen above, the strange placement of the apostrophes messes up the last line. The furthest I managed to get was having it display the real '12.28' part.
Otherwise, the error I get is, as expected (commented):
% Undefined function 'exp' for input arguments of type 'char'.
% Error in phasor_to_polar_BROKEN (line 13)
% disp(['V=',num2str(MagV,'%3.4g')], [exp(',num2str(PhaseVDeg,''%3.4g'),'j)'])
How do I fix this code to run as it should; displaying the Real and Imaginary properly?

 채택된 답변

Star Strider
Star Strider 2020년 1월 26일

1 개 추천

There is a missing single quote
disp(['V=',num2str(MagV,'%3.4g'),...
exp(',num2str(PhaseVDeg,'%3.4g'),'j)'])
↑ ← HERE
The correct line should be:
disp(['V=',num2str(MagV,'%3.4g'),...
'exp(',num2str(PhaseVDeg,'%3.4g'),'j)'])
It then produces:
V=12.28exp(-21.85j)
as intended.

댓글 수: 2

Kay Sho
Kay Sho 2020년 1월 26일
Thank you!
Star Strider
Star Strider 2020년 1월 26일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

태그

질문:

2020년 1월 26일

댓글:

2020년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by