Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Ordering of output question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28263] Re: [mg28226] Ordering of output question
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Fri, 6 Apr 2001 01:53:12 -0400 (EDT)
  • References: <200104050700.DAA26439@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Evaluation of your code below gave

f(z) = f[z]
Let z = x + I y
f(x + I*y) = f[x + I*y] = Re[f[x + I*y]] + I* Im[f[x + I*y]].
The real part of f(z) = I + I*z is Re[f[x + I*y]] and the imaginary part is
Im[f[x + I*y]].

so I imagine some kind of assignment or rule saying that z = x + I*y was
lost somewhere. Now, I guess you are mainly concerned with *displaying* a
complex number in the form a + I b. Forcing Mathematica to change the order
in which expressions are internally handled would be difficult and, in the
end, useless. If a canonical order is used to internally handle expressions,
then so be it. For example, if we were to use variables {w, v, u} (in that
precise order), w and v real, in your example, then

In[2]:=
ComplexExpand[I + I*u /. u -> w + I*v]
Out[2]=
-v + I*(1 + w)

which is the way you would like a complex number to be displayed, and this
is because v comes before w in canonical order. However, if you want only an
*external* way of displaying a result, i.e., only for visual purposes, you
needn't go into so much trouble. I think defining one fCZ and one fCXY is
unnecesary, since a single function f, say, can handle its argument either
in the form z or in the form x +I y. Thus, if you define f as follows, and
then extract the real and imaginary parts

In[3]:=
f[z_] := I + I z
In[4]:=
reim = #[ComplexExpand[f[z] /. z -> x + I y]] & /@ {Re, Im}
Out[4]=
{-y, 1 + x}

you can then print something like

In[5]:=
Print["The real part of f(z) = ", f[z], " is ", reim[[1]],
    " and the imaginary part is ", reim[[2]],
    ", where z = x + I y\n so that ", f[z], "= ", reim[[1]], " + I (",
    reim[[2]], ")."];
"The real part of f(z) = "I +
  I*z" is "-y" and the imaginary part is "1 +
  x", where z = x + I y so that "I +
  I*z"= "-y" + I ("1 + x")."

BTW, in your original print statement, I think saying Print["f(z) = ",
f[z]]; could be misleading. f(z) is *not* equal to f[z]. You might say
something like "In Mathematica the function f(z) is written as f[z], because
round parentheses are only used for grouping purposes", or something like
that.

Tomas Garza
Mexico City



-----Original Message -----
From: "John Todd" <johntodd at fake.com>
To: mathgroup at smc.vnet.net
Subject: [mg28263] [mg28226] Ordering of output question


> Hello,
> I'm trying to get the output of the following to be in
> standard complex number form, i.e. a + ib:
>
> Clear[x, y, z];
> Clear[fCZ, fCXY];
> x /: Im[x] = 0;
> x /: Re[x] = x;
> y /: Im[y] = 0;
> y /: Re[y] = y;
> fCZ[z_] := \[ImaginaryI] z + \[ImaginaryI];
> fCXY = ComplexExpand[f[x + \[ImaginaryI] y]];
> Print["f(z) = ", f[z]];
> Print["Let z = x + \[ImaginaryI]y"];
>
> (* The following line is where my question pertains*)
> Print["f(x + \[ImaginaryI]y) = ", fCXY, " = ", Re[fCXY],
>     " + \[ImaginaryI]"Im[fCXY], "."];
>
> Print["The real part of f(z) = ", fCZ[z], " is ", Re[fCXY],
>     " and the imaginary part is ", Im[fCXY], "."];
>
>      If you evaluate the above, you'll find that the line directly
> below the commented line has its final outpu as -y + i(x + 1) which is
> what I want.  However, my means of getting it to look that way seem a
> bit inelegant,, and I feel certain there is a better way.  I do
> realize that looking at the expression with TreeForm[], I can extract
> whatever I want out of an expression, but that also seems inelegant.
> What I feel must be possible is to set up some sort of a pattern or
> transformation rule which will say in effect, "Place the output in
> this form, i.e. a + ib, regardless of what a and b are".  I ask this
> question not only for the specific example given but also in a broader
> sense because I will and have wanted to display expressions in a
> certain format, but have always had to resort to the kinds of
> contrivances already mentioned.
>      Before submitting my question I perused the sections on Patterns
> and the section on Transformation Rules in Wolfram's 4th edition
Mathematica
> book.  If I missed a glaring answer to my question, I apologize.
>
> Thanks again,
>
> JT
>




  • Prev by Date: Re: Notebooks do not display correctly in 1024X768
  • Next by Date: Re:complex coefficients and rules...
  • Previous by thread: Ordering of output question
  • Next by thread: Re: Ordering of output question