Broken code on phasor representation
Show older comments
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?
Accepted Answer
More Answers (0)
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!