Ask Your Question
3

check if the result is a real number

asked 2012-05-04 05:39:24 -0500

disi gravatar image

I get several results and want to check, which one is a real number. From trial and error, I can see that maxSol[2][x] is the only plausable solution.

Is there something like isReal()?

my attempt (don't laugh) ;)

for i in maxSol: print RealField(50)(i)

where I obviously get: TypeError: Unable to convert x (='.....

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2012-05-04 05:59:26 -0500

niles gravatar image

updated 2012-05-04 06:02:33 -0500

I think "a in RR" is what you want to use. Your first attempt could work too, using a try/except block.

For testing integrality, or rationality, "in ZZ" and "in QQ" work similarly.

And if you know the numbers you're checking are complex, you could also test to see whether their imaginary parts are zero.

edit flag offensive delete link more

Comments

Thanks so much :)

disi gravatar imagedisi ( 2012-05-04 06:05:48 -0500 )edit

for self reference, this is what I got:

disi gravatar imagedisi ( 2012-05-04 06:12:16 -0500 )edit

It is not so easy: arccos(2) in RR is evaluated as true, while arccos(2).n() is NaN. The best we found with my student is a.n() != NaN and a.n().is_real() -- is this too complicated? See also http://bit.ly/LndAoI

Robert Samal gravatar imageRobert Samal ( 2012-05-10 01:16:21 -0500 )edit
0

answered 2012-05-04 06:13:12 -0500

disi gravatar image

again, this works perfect :)

for a in maxSol:
    if a[x] in RR:
        print RealField(50)(a[x])
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-05-04 05:39:24 -0500

Seen: 957 times

Last updated: May 04 '12