Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, When I operate with complex numbers in Exponential Form, Mathematica yields in complex form. How can I operate with Exponential Form. For example, In: h=a E^(I b)+ c E^(I d) Out: f E^(I g) I tried with Abs[h] E^(Arg[h]) but it does not work Thanks
Post Follow-up to this messageYou can use ComplexExpand to develop expressions for the modulus f and the
argument g.
h = a E^(I b) + c E^(I d);
ComplexExpand[Abs[h]];
f = Simplify[%]
Sqrt[a^2 + c^2 + 2*a*c*Cos[b - d]]
g = ComplexExpand[Arg[h], TargetFunctions -> {Re, Im}]
ArcTan[a Cos[b] + c Cos[d], a Sin[b] + c Sin[d]]
These can then be combined in a definition for the exponential form.
expform[a_, b_, c_, d_] = f*E^(I*g)
E^(I*ArcTan[a*Cos[b] + c*Cos[d], a*Sin[b] +
c*Sin[d]])*Sqrt[a^2 + c^2 + 2*a*c*Cos[b - d]]
As long as you use exact input you will obtain the exponential form.
expform[1, 1, 1, 1]
2*E^I
expform[3, 2, -5, 2]
2*E^(I*(2 - Pi))
But if you enter an approximate number, then Mathematica will reduce to a
complex number.
expform[3.0, 2, -5, 2]
0.832294 - 1.81859 I
An alternative is not to combine the modulus and argument into one
expression but write a routine that keeps them separate.
modulusarg[a_, b_, c_, d_] = {f, g}
{Sqrt[a^2 + c^2 + 2*a*c*Cos[b - d]],
ArcTan[a*Cos[b] + c*Cos[d], a*Sin[b] + c*Sin[d]]}
Then
modulusarg[3.0, 2, -5, 2]
{2., -1.14159}
Or we could write a definition that puts the modulus and argument in
HoldForm to prevent full evaluation by Mathematica.
expform2[a_, b_, c_, d_] :=
With[{modulus = Sqrt[a^2 + c^2 + 2*a*c*Cos[b - d]],
arg = ArcTan[a*Cos[b] + c*Cos[d],
a*Sin[b] + c*Sin[d]]}, HoldForm[modulus]*
Exp[I*HoldForm[arg]]]
You then have to do a ReleaseHold to obtain the final numerical expression.
expform2[3.0, 2, -5, 2]
% // ReleaseHold
E^(-1.14159 I)2.
0.832294 - 1.81859 I
David Park
djmp@earthlink.net
http://home.earthlink.net/~djmp/
From: Miguel [mailto:m.glanda@iberdrola.es]
Hi,
When I operate with complex numbers in Exponential Form, Mathematica
yields in complex form. How can I operate with Exponential Form. For
example,
In: h=a E^(I b)+ c E^(I d)
Out: f E^(I g)
I tried with Abs[h] E^(Arg[h]) but it does not work
Thanks
Post Follow-up to this messageMiguel schrieb:
> Hi,
> When I operate with complex numbers in Exponential Form, Mathematica
> yields in complex form. How can I operate with Exponential Form. For
> example,
>
> In: h=a E^(I b)+ c E^(I d)
> Out: f E^(I g)
>
> I tried with Abs[h] E^(Arg[h]) but it does not work
>
> Thanks
>
{f,g} = Simplify[ComplexExpand[#[a*E^(I*b) + c*E^(I*d)]& /@ {Abs, Arg}]]
-->
{Sqrt[a^2 + c^2 + 2*a*c*Cos[b - d]],
ArcTan[a*Cos[b] + c*Cos[d], a*Sin[b] + c*Sin[d]]}
--
Peter Pein, Berlin
GnuPG Key ID: 0xA34C5A82
http://people.freenet.de/Peter_Berlin/
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.