Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14958

Re: How to remove the "0." from "0. + 1.41774i"

From Sseziwa Mukasa <mukasa@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: How to remove the "0." from "0. + 1.41774i"
Date 2013-06-21 09:45 +0000
Message-ID <kq17bv$goc$1@smc.vnet.net> (permalink)
References <20130620084452.627F569EF@smc.vnet.net> <58732FA6-FDFE-4100-8637-926219C678F6@gmail.com> <CAJxy_SqurCkArZaLNQDN+35u3YT8XjAL7g7wsL9cvnSOV9MLKg@mail.gmail.com>
Organization Time-Warner Telecom

Show all headers | View raw


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
> >
>
>

Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: How to remove the "0." from "0. + 1.41774i" Sseziwa Mukasa <mukasa@gmail.com> - 2013-06-21 09:45 +0000
  Re: How to remove the "0." from "0. + 1.41774i" Richard Fateman <fateman@cs.berkeley.edu> - 2013-06-22 07:29 +0000
  Re: How to remove the "0." from "0. + 1.41774i" Christoph Lhotka <christoph.lhotka@univie.ac.at> - 2013-06-23 00:40 +0000
  Re: How to remove the "0." from "0. + 1.41774i" Richard Fateman <fateman@eecs.berkeley.edu> - 2013-06-23 00:40 +0000
  Re: How to remove the "0." from "0. + 1.41774i" Christoph Lhotka <christoph.lhotka@univie.ac.at> - 2013-06-23 00:41 +0000

csiph-web