# how to tell sage to give numeric result.

If I give sage the following:

sin(2*pi/30)


It give in return

sin(1/15*pi)


While I want the numeric value. I know that the most accurate result is the one given by sage by I need to compare it with another result I gut from numerical calculation.

edit retag close merge delete

Sort by » oldest newest most voted You can use the numerical_approx functions/methods. Type "help(numerical_approx)" for a full description. It can be called in lots of ways -- too many, probably! -- and you can specify the precision in bits or in decimal digits:

sage: q = sin(2*pi/30)
sage:
sage: numerical_approx(q)
0.207911690817759
sage: q.numerical_approx()
0.207911690817759
sage: q.n()
0.207911690817759
sage:
sage: q.n(prec=100) # bits
0.20791169081775933710174228441
sage: q.n(digits=50) # decimal digits
0.20791169081775933710174228440512516621658476062772


You can also use

sage: n(q)
0.207911690817759
sage: N(q)
0.207911690817759


but I'll be honest, I don't like that very much. I use n and N all the time as variables, so these aren't very useful for me.

UPDATE:

I should have mentioned another way -- you can often coerce objects from one form to another by calling the desired ring. So these work too:

sage: RR
Real Field with 53 bits of precision
sage: RR(q)
0.207911690817759
sage: RealField(100)
Real Field with 100 bits of precision
sage: RealField(100)(q)
0.20791169081775933710174228441

more

this style also work

N(sin(2*pi/30), digits=30)

more