Prev: Automatic Differentiation of mathematica code
Next: Export[] hi-res JPEG not affecting Axes|Plot Label->
From: Marco Masi on 28 Jun 2010 02:30 Yes, thank you, that brough me a step forward (and yes, I forgot to square the Abs value in the previous example... sorry for that). However, there is still a step which I can't accomplish. Please try the following: FullSimplify[ ComplexExpand[ Abs[1/2 (A1 E^(I \[Phi]1) - A2 E^(I \[Phi]2) + A1 E^(I \[Phi]1) Cos[Sqrt[2] c z] + A2 E^(I \[Phi]2) Cos[Sqrt[2] c z])]]^2] I would like to have Mathematica avoiding one of the resulting Cos[2 Sqrt[2] c z] expression, and maintain both as Cos[Sqrt[2] c z], and then simplify. How should I proceed? Regards, Mark. --- Dom 27/6/10, Murray Eisenberg <murray(a)math.umass.edu> ha scritto: Da: Murray Eisenberg <murray(a)math.umass.edu> Oggetto: Re: Absolute value A: mathgroup(a)smc.vnet.net Data: Domenica 27 giugno 2010, 17:37 Actually, the correct answer should be the square-root of what you claim is the answer. In such problems, remember the crucial fact that Mathematica does not "know " that you intended phi1 and phi2 to be real, and hence it does not attempt further simplification. By default, symbolic quantities in Mathematica are interpreted as potentially complex rather than real when they appear in expressions involving complex numbers. In such situations, ComplexExpand is your friend: ComplexExpand[Abs[Exp[I phi1] + Exp[I*phi2]]] // InputForm Sqrt[(Cos[phi1] + Cos[phi2])^2 + (Sin[phi1] + Sin[phi2])^2] ComplexExpand[Abs[Exp[I phi1]+Exp[I*phi2]]] // Simplify // InputForm Sqrt[2 + 2*Cos[phi1]*Cos[phi2] + 2*Sin[phi1]*Sin[phi2]] (I used InputForm here only in order to create one-dimensional output. In actual use you wouldn't do that, so you'd actually see the two-dimensional square-root notation.) On 6/27/2010 4:55 AM, Marco Masi wrote: > I would like to calculate the absolute value of complex quantities. For example Abs[Exp[I phi1]+Exp[I*phi2]], which sould give 2 (1+cos(phi1-phi2)). However it does not work. I tried to use real numbers as assumtion, but it always answers "Abs[Exp[I phi1]+Exp[I*phi2]]". What am I doing wrong? > > Regards, Mark. > -- Murray Eisenberg murray(a)math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305
From: Patrick Scheibe on 28 Jun 2010 02:34 Hi, try to use ComplexExpand. Cheers Patrick On Sun, 2010-06-27 at 04:55 -0400, Marco Masi wrote: > I would like to calculate the absolute value of complex quantities. For example Abs[Exp[I phi1]+Exp[I*phi2]], which sould give 2 (1+cos(phi1-phi2)). However it does not work. I tried to use real numbers as assumtion, but it always answers "Abs[Exp[I phi1]+Exp[I*phi2]]". What am I doing wrong? > > Regards, Mark. >
From: David Park on 28 Jun 2010 02:34 Maybe someone will give a more direct calculation, but otherwise this is slightly on the tricky side. Paste the following into a notebook and evaluate. Print["Initial complex expression:"] step1 = Exp[I phi1] + Exp[I*phi2] Print["Convert to trigonometric form."] step2 = step1 // ExpToTrig Print["Calculate the Abs value squared and expand to real + imaginary \ form, with the imaginary part zero."] step3 = ComplexExpand[Abs[step2]^2, TargetFunctions -> {Re, Im}] Print["Use TrigFactor."] step4 = step3 // TrigFactor Print["Take the square root and simplify"] Simplify[Sqrt[step4], {phi1, phi2} \[Element] Reals] 1) It seemed easier to calculate Abs^2 and then take the square root at the end. 2) We need to use ComplexExpand to expand a complex expression to the form (real part) + I (imaginary part) and since the imaginary part is already zero we have to use the TargetFunctions option to get this to evaluate to the extent that we want. 3) We have to use TrigFactor to obtain the trigonometric form you are looking for. How did I know that? I didn't really. I tried TrigExpand, TrigReduce and then TrigFactor. But since the expression looks like one that could be factored I should have tried TrigFactor first. 4) Finally we take the square root and simplify using real variable assumptions. Both the Complex and ComplexExpand Function pages need more explicit notes and examples to point users in the right direction. David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ From: Marco Masi [mailto:marco.masi(a)ymail.com] I would like to calculate the absolute value of complex quantities. For example Abs[Exp[I phi1]+Exp[I*phi2]], which sould give 2 (1+cos(phi1-phi2)). However it does not work. I tried to use real numbers as assumtion, but it always answers "Abs[Exp[I phi1]+Exp[I*phi2]]". What am I doing wrong? Regards, Mark.
From: Bob Hanlon on 28 Jun 2010 02:34 Presumably, you meant the square of your expression expr = Abs[Exp[I*phi1] + Exp[I*phi2]]^2; ComplexExpand[expr, TargetFunctions -> {Re, Im}] // FullSimplify 2 (cos(phi1-phi2)+1) Bob Hanlon ---- Marco Masi <marco.masi(a)ymail.com> wrote: ============= I would like to calculate the absolute value of complex quantities. For example Abs[Exp[I phi1]+Exp[I*phi2]], which sould give 2 (1+cos(phi1-phi2)). However it does not work. I tried to use real numbers as assumtion, but it always answers "Abs[Exp[I phi1]+Exp[I*phi2]]". What am I doing wrong? Regards, Mark.
From: Peter Pein on 29 Jun 2010 06:57 Am Mon, 28 Jun 2010 06:30:57 +0000 (UTC) schrieb Marco Masi <marco.masi(a)ymail.com>: > Yes, thank you, that brough me a step forward (and yes, I forgot to > square the Abs value in the previous example... sorry for that). > > However, there is still a step which I can't accomplish. Please try > the following: FullSimplify[ ComplexExpand[ Abs[1/2 (A1 E^(I \[Phi]1) > - A2 E^(I \[Phi]2) + A1 E^(I \[Phi]1) Cos[Sqrt[2] c z] + A2 E^(I > \[Phi]2) Cos[Sqrt[2] c z])]]^2] > > I would like to have Mathematica avoiding one of the resulting Cos[2 > Sqrt[2] c z] expression, and maintain both as Cos[Sqrt[2] c z], and > then simplify. How should I proceed? > > Regards, Mark. > Hi Mark, try squaring the absolute value before using ComplexExpand: FullSimplify[ComplexExpand[ Abs[(1/2)*(A1*E^(I*\[Phi]1) - A2*E^(I*\[Phi]2) + A1*E^(I*\[Phi]1)*Cos[Sqrt[2]*c*z] + A2*E^(I*\[Phi]2)*Cos[Sqrt[2]*c*z])]^2]] --> (1/4)*Abs[A2*E^(I*\[Phi]2)*(-1 + Cos[Sqrt[2]*c*z]) + A1*E^(I*\[Phi]1)*(1 + Cos[Sqrt[2]*c*z])]^2 but I would prefer: Collect[ ComplexExpand[ Abs[(1/2)*(A1*E^(I*\[Phi]1) - A2*E^(I*\[Phi]2) + A1*E^(I*\[Phi]1)*Cos[Sqrt[2]*c*z] + A2*E^(I*\[Phi]2)*Cos[Sqrt[2]*c*z])]^2, TargetFunctions -> {Re,Im}], A1 | A2, TrigFactor] which returns A1^2*Cos[(c*z)/Sqrt[2]]^4 + A2^2*Sin[(c*z)/Sqrt[2]]^4 - (1/2)*A1*A2*Cos[\[Phi]1 - \[Phi]2]*Sin[Sqrt[2]*c*z]^2 Peter
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Automatic Differentiation of mathematica code Next: Export[] hi-res JPEG not affecting Axes|Plot Label-> |