Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to remove the "0." from "0. + 1.41774i"
Replies: 9   Last Post: Jun 22, 2013 8:41 PM

 Messages: [ Previous | Next ]
 Sseziwa Mukasa Posts: 108 Registered: 8/26/07
Re: How to remove the "0." from "0. + 1.41774i"
Posted: Jun 21, 2013 5:45 AM

It's a precision issue, the documentation on rationalize says:

Rationalize[x] yields x unchanged if there is no rational number close enough to x to satisfy the condition =E2=88=AA p/q - x =E2=88=AA < c/q^2, with c chosen to be 10^-4.
Rationalize[x, 0] converts any x to rational form.

So:

(Debug) In[17]:= nuChop[t_] := Rationalize[Chop[t], 0];
A = {{-1.2, 1.5}, {-2.3, 1.2}};
eigval1 = Eigenvalues[A][[1]]
nuChop[eigval1]
(Debug) Out[19]= 2.77556*10^-17 + 1.41774 I
(Debug) Out[20]= (116833629 I)/82408088

But I don't find (116833629 I)/82408088 more visually useful than 0. + 1.41774 I.

However here's another approach:

(Debug) In[32]:= suppressMachinePrecisionZeros[Complex[a_, b_]] :=
SetPrecision[Chop[a], \$MachinePrecision] +
SetPrecision[Chop[b], \$MachinePrecision] I
(Debug) In[33]:= suppressMachinePrecisionZeros /@ Eigenvalues[A]
(Debug) Out[33]= {1.417744687875782 I, -1.417744687875782 I}

On Jun 20, 2013, at 8:15 AM, Mike Bayville <mike.bayville@gmail.com> wrote:

> Thanks, but Rationalize works in the manner you executed it; however, it does not work like this...
>
> In[216]:= nuChop[t_] = Rationalize[t];
> A = {{-1.2, 1.5}, {-2.3, 1.2}};
> eigval1 = Eigenvalues[A][[1]]
> nuChop[eigval1]
>
> Out[218]= 2.7755576*10^-17 + 1.4177447 I
>
> Out[219]= 2.7755576*10^-17 + 1.4177447 I
>
>
> On Thu, Jun 20, 2013 at 7:54 AM, Sseziwa Mukasa <mukasa@gmail.com> wrote:
> (Debug) In[3]:= Rationalize[0. + 1.41774 I]
> (Debug) Out[3]= (70887 I)/50000
>
> That has it's own problems with respect to large values in the numerator or denominator.
>
> On Jun 20, 2013, at 4:44 AM, Mike Bayville <mike.bayville@gmail.com> wrote:
>

> > Can anyone suggest a built-in function for removing the "0." from "0. + 1.41774i"?
> >
> > Thanks!
> >
> > Mike
> >
> > INPUT
> > A={{-1.2, 1.5}, {-2.3, 1.2}};
> > Clear[eigenvalue];
> > {eigenvalue[1], eigenvalue[2]} = Chop[Eigenvalues[A]]
> > Chop[eigenvalue[1]]
> > Chop[eigenvalue[2]]
> >
> > OUTPUT
> > {0. + 1.41774i, 0. - 1.41774i}
> > 0. + 1.41774i
> > 0. - 1.41774i
> >

>
>

Date Subject Author
6/21/13 Sseziwa Mukasa
6/22/13 Richard Fateman
6/22/13 Christoph Lhotka
6/22/13 Richard Fateman
6/22/13 Christoph Lhotka