[Date Index]
[Thread Index]
[Author Index]
Re: Re: Ordering of output question
*To*: mathgroup at smc.vnet.net
*Subject*: [mg28281] Re: [mg28252] Re: Ordering of output question
*From*: Mianlai Zhou <lailai at carmen.nikhef.nl>
*Date*: Sat, 7 Apr 2001 03:44:39 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
Hello, I think you may be happy to use MakeBoxes to force the output of
complex number in Mathematica as "a + b i". An example is:
Unprotect[Complex];
Complex /: MakeBoxes[Complex[x_, y_], StandardForm] :=
RowBox[{MakeBoxes[x, StandardForm], " + ", MakeBoxes[y, StandardForm],
" i"}];
Protect[Complex];
But please be careful with this. Otherwise it will cause unexpected
conflicted with its internal definitions. I suggest you read the Help of
Mathematica on Format and MakeBoxes first.
Mianlai Zhou
NIKHEF, Amsterdam
On Fri, 6 Apr 2001, John Todd wrote:
> On 5 Apr 2001 03:19:53 -0400, johntodd at fake.com (John Todd) wrote:
>
> >Hello,
> > I'm trying to get the output of the following to be in
> >standard complex number form, i.e. a + ib:
>
> Actually, I made a mistake in the code I originally posted and didn't
> catch it because I hadn't restarted the kernel. It should read as
> follows:
>
> Clear[u, v, x, y, z, gRefCZ, gImfCZ, gEqRefCZ, gEqImfCZ,
> gDomToRangeRe,
> gDomToRangeIm];
> Clear[f, 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[fCZ[x + \[ImaginaryI] y]];
> gRefCZ = Re[fCXY];
> gImfCZ = Im[fCXY];
> gEqRefCZ = u == gRefCZ;
> gEqImfCZ = v == gImfCZ;
> gDomToRangeRe = Solve[gEqRefCZ, y];
> gDomToRangeIm = Solve[gEqImfCZ, x];
> Print["Given:\nf(z) = ", fCZ[z]];
> Print["Let z = x + \[ImaginaryI]y"];
>
> (* The following line is where my question pertains*)
> Print["f(x + \[ImaginaryI]y) = ", fCZ[x + \[ImaginaryI] y], " = ",
> fCXY,
> " = ", gRefCZ, " + \[ImaginaryI](", gImfCZ, ")."];
>
> Print["The real part of f(z) = ", fCZ[z], " is ", gRefCZ,
> " and the imaginary part is ", gImfCZ, "."];
>
>
> > 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
>
>
> Sorry about that,
>
> JT
>
Prev by Date:
**Re: Howto vonvert a list of functions in a list valued function**
Next by Date:
**Re: A universal simulation interface: database, input/output, plotting and visualization**
Previous by thread:
**Re: Ordering of output question**
Next by thread:
**Help with Fold/outer one-liner (II)**
| |