[Date Index]
[Thread Index]
[Author Index]
Re: Ordering of output question
*To*: mathgroup at smc.vnet.net
*Subject*: [mg28269] Re: Ordering of output question
*From*: johntodd at fake.com (John Todd)
*Date*: Sat, 7 Apr 2001 03:44:28 -0400 (EDT)
*References*: <200104050700.DAA26439@smc.vnet.net> <9ajns1$sg2@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
On 6 Apr 2001 02:31:29 -0400, Tomas Garza <tgarza01 at prodigy.net.mx>
wrote:
>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]].
Sorry about that, I posted a correction (too late obviously)...
>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
I'm not particularly interested in changing the way expressions are
handled internally, rather I want a way to take what Mathematica returns and
make it conform to a particular format.
>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
I agree with you, I actually defined one as fCZ := and one as fCXY =
and the reason I did that, is that I figured rather than continually
evaluating ComplexExpand[fCZ[x + iy]] everytime I needed that form, I
would simply store it for future use. The more I use Mathematica, the more I
realize the need for code organization and that is the reason for my
perhaps arcane function and variable names. I'm basically trying to
come up with a Hungarian notation for my Mathematica code/notebooks. So, for
example fCZ means a function that takes a complex operand z and fCXY
means that that is the form in which I did the Complex expand on fCZ.
Since, I'm treating fCXY as a variable, I actually need to prepend it
with a g, which is what I'm using to denote globally declared
variables.
>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.
The only reason I use the f(z) in the Print statement is for output
purposes, because others not familiar with Mathematica will be seeing some of
the output and I want it to appear as mathematically 'familiar' as
possible, which is also the reason for my wanting to be able to show
the output in a particular manner
..
>Tomas Garza
>Mexico City
Thanks for your help, especially the code because it's helped me to
learn yet more about setting up expressions in Mathematica...
JT
Prev by Date:
**Re: A universal simulation interface: database, input/output, plotting and visualization**
Next by Date:
**Removing Audio "Clicking"**
Previous by thread:
**Re: Ordering of output question**
Next by thread:
**Re: Ordering of output question**
| |