Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #14943 > unrolled thread
| Started by | Mike Bayville <mike.bayville@gmail.com> |
|---|---|
| First post | 2013-06-20 08:01 +0000 |
| Last post | 2013-06-24 02:50 +0000 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
How to remove the "0." from "0. + 1.41774i" Mike Bayville <mike.bayville@gmail.com> - 2013-06-20 08:01 +0000
Re: How to remove the "0." from "0. + 1.41774i" cj.girlie@gmail.com - 2013-06-21 09:43 +0000
Re: How to remove the "0." from "0. + 1.41774i" "Nasser M. Abbasi" <nma@12000.org> - 2013-06-21 09:42 +0000
How to remove the "0." from "0. + 1.41774i" [Revised] Mike Bayville <mike.bayville@gmail.com> - 2013-06-21 09:43 +0000
Re: How to remove the "0." from "0. + 1.41774i" [Revised] Murray Eisenberg <murray@math.umass.edu> - 2013-06-22 07:27 +0000
Re: How to remove the "0." from "0. + 1.41774i" [Revised] Fred Simons <f.h.simons@tue.nl> - 2013-06-24 02:50 +0000
| From | Mike Bayville <mike.bayville@gmail.com> |
|---|---|
| Date | 2013-06-20 08:01 +0000 |
| Subject | How to remove the "0." from "0. + 1.41774i" |
| Message-ID | <kpucst$9f7$1@smc.vnet.net> |
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
[toc] | [next] | [standalone]
| From | cj.girlie@gmail.com |
|---|---|
| Date | 2013-06-21 09:43 +0000 |
| Message-ID | <kq178p$gnq$1@smc.vnet.net> |
| In reply to | #14943 |
On Thursday, June 20, 2013 4:01:33 AM UTC-4, Mike Bayville 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
Try this
ToExpression[StringReplace[ToString[0. + 1.41774 i], "0." -> "" ]]
Effective but not elegant
[toc] | [prev] | [next] | [standalone]
| From | "Nasser M. Abbasi" <nma@12000.org> |
|---|---|
| Date | 2013-06-21 09:42 +0000 |
| Message-ID | <kq175k$gne$1@smc.vnet.net> |
| In reply to | #14943 |
On 6/20/2013 3:01 AM, Mike Bayville 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
>
Seems related to the thread "Multiplication by 0" 2 days ago?
I do not it is allowed to have a number with exact real part
and machine reals imaginary part. The complex system has to have
both parts either exact or both parts be machine reals. Can't mix
and match.
So you can't have
0 + 2. I
But you can have
0 + 2 I ===> which is 2I
and can have this
0. + 2. I
btw, I tested this on that other system, that starts its name
by "M" and ends with "E" and it behaves the same way:
-------------------------------
A:=Matrix([[-1.2, 1.5], [-2.3, 1.2]]):
a:=eig(A):
a[1];
-17
2.77555756156289 10 + 1.41774468787578 I
fnormal(%);
0. + 1.417744688 I
-----------------------------------
see:
In[33]:= 2 + 2. I
Out[33]= 2. + 2. I
Why is it important for you to remove the 0. from the display?
You can use Im and Re to obtain the real and imaginary parts of
complex number any time.
--Nasser
[toc] | [prev] | [next] | [standalone]
| From | Mike Bayville <mike.bayville@gmail.com> |
|---|---|
| Date | 2013-06-21 09:43 +0000 |
| Subject | How to remove the "0." from "0. + 1.41774i" [Revised] |
| Message-ID | <kq177h$gnm$1@smc.vnet.net> |
| In reply to | #14943 |
I have some to realize that I failed to describe the context of my request.
I am hope to identify or create a function, e.g., mikechop[t_], such that the argument could be a real or complex number, and if it is a complex number such as:
0. + 1.41774i
or
1.2313 x 10^(-16) + 1.41774i
the output will be:
1.41774i
otherwise it will be the real or complex number that was input.
This is for inclusion in code that I write.
Sorry for not properly describing the end use.
Humbly,
Mike
On Thursday, June 20, 2013 4:01:33 AM UTC-4, Mike Bayville 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
[toc] | [prev] | [next] | [standalone]
| From | Murray Eisenberg <murray@math.umass.edu> |
|---|---|
| Date | 2013-06-22 07:27 +0000 |
| Subject | Re: How to remove the "0." from "0. + 1.41774i" [Revised] |
| Message-ID | <kq3jlb$nee$1@smc.vnet.net> |
| In reply to | #14943 |
Unless you'd be satisfied to have just a display form with no "0." included, e.g., as a string, I don't see how you can do what you ask. You might be tempted to try something like:
imchop[z_] :=
Which[z \[Element] Reals, z,
Head[z] == Complex && Re[z] != 0, z,
Head[z] == Complex && Re[z] == 0, Im[z] I]
But it won't handle the case at issue, e.g.:
imchop[0. + 1.41774 I]
0. + 1.41774 I
And the reason is that after extracting the imaginary part 1.41774 and multiplying by I, you have a number whose FullForm is
Complex[0.`, 1.417741]
and hence will display as the very same 0. + 1.41774 I.
> I have some to realize that I failed to describe the context of my request.
>
> I am hope to identify or create a function, e.g., mikechop[t_], such that the argument could be a real or complex number, and if it is a complex number such as:
>
> 0. + 1.41774i
>
> or
>
> 1.2313 x 10^(-16) + 1.41774i
>
> the output will be:
>
> 1.41774i
>
> otherwise it will be the real or complex number that was input.
>
> This is for inclusion in code that I write.
>
> Sorry for not properly describing the end use.
>
> Humbly,
>
> Mike
>
>
>
>
>
> On Thursday, June 20, 2013 4:01:33 AM UTC-4, Mike Bayville 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
---
Murray Eisenberg murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2838 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
[toc] | [prev] | [next] | [standalone]
| From | Fred Simons <f.h.simons@tue.nl> |
|---|---|
| Date | 2013-06-24 02:50 +0000 |
| Subject | Re: How to remove the "0." from "0. + 1.41774i" [Revised] |
| Message-ID | <kq8c51$6o6$1@smc.vnet.net> |
| In reply to | #14943 |
Want you want to do can be achieved by changing the way Mathematica
prints complex numbers, for example in the following way:
In[1]:= 0.+4.23I
4.23+0. I
3.5+4.2 I
Out[1]= 0. +4.23 I
Out[2]= 4.23 +0. I
Out[3]= 3.5 +4.2 I
In[4]:= MakeBoxes[Complex[a_ /; Chop[a]==0., b_] , StandardForm] :=
RowBox[{MakeBoxes[b, StandardForm]," ", MakeBoxes[I,StandardForm]}];
MakeBoxes[Complex[a_ , b_/;Chop[b]==0] , StandardForm] := MakeBoxes[a,
StandardForm];
In[6]:= 0.+4.23I
4.23+0. I
3.5+4.2 I
Out[6]= 4.23 I
Out[7]= 4.23
Out[8]= 3.5 +4.2 I
Be careful; there might be side effects.
Fred Simons
Eindhoven University of Technology
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web