Converting Complex numbers in Polar/Cartesian form to exponential form.
32 views (last 30 days)
Show older comments
I was wondering if anybody knows a way of having matlab convert a complex number in either polar or cartesian form into exponential form and then actually display the answer in the form ' z=re^itheta'
I know the functions cart2pol and pol2cart can be used to convert between cartesian and polar form but i am yet to find a way to display an answer in exponential form and was wondering if this was indeed possible at all
thanks
0 Comments
Answers (2)
Travis Kent
on 17 Dec 2020
i know this is years late but i just did a similar thing; *i did not author the code to convert rectangular to polar, just the part to answer your question to display the output in exponential. you would have to alter it to either accept rectangular or cartesean, id assume by input() function
function[]=r2p(z)
% z=a+ib where a is real part & b is imaginary part
% magnitude=sqrt(a^2+b^2)
% angle=inver_tan(b/a)
a=real(z);
b=imag(z);
magnitude=sqrt(a^2+b^2);
disp('magnitude:')
disp(magnitude);
if a>0 && b>0
angle=(atan(abs(b/a)))*180/pi;
disp('angle in degrees:')
disp(angle);
elseif a<0 && b>0
angle=180-((atan(abs(b/a)))*180/pi);
disp('angle in degrees:')
disp(angle);
elseif a<0 && b<0
angle=180+((atan(abs(b/a)))*180/pi);
disp('angle in degrees:')
disp(angle);
elseif a>0 && b<0
angle=-((atan(abs(b/a)))*180/pi);
disp('angle in degrees:')
disp(angle);
end
r="e^i";
z="Z="
p=[z,magnitude,r,angle];
out=sprintf('%s',string(p));
fprintf(out)
end
say r2p(10+10i) is entered in command window it outputs:
>>r2p(10+10i)
magnitude:
14.1421
angle in degrees:
45
Z=14.1421e^i45
0 Comments
Star Strider
on 20 Mar 2015
I’m not exactly certain, but as I understand it, you want phasor notation.
This works:
phasr = @(z) [abs(z) angle(z)];
Z = 1 + 1i*1;
ph = phasr(Z);
retheta = ph(1)*exp(1i*ph(2))
2 Comments
Star Strider
on 20 Mar 2015
Try this:
phasr = @(z) [abs(z) angle(z)];
Z = 8 + 1i*7;
ph = phasr(Z);
retheta = sprintf('%.1f %+.1fi', ph(1), ph(2))
It produces:
retheta =
10.6 +0.7i
See Also
Categories
Find more on Matrix Indexing 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!