First time here? Check out the FAQ!

Ask Your Question
1

Setting Precision in Sage

asked 14 years ago

willmwade gravatar image
integral(integral(e^(-0.00260657639223762*(h - 11.1600000000000)^2 - 1.34372480515*(d - 2.85000000000000)^2)/pi, d, 0,Infinity), h, 0, Infinity).n()

I have been working through an error I am receiving with the above command. The error I get when I run it is:

TypeError: Error executing code in Maxima
CODE:
    sage297 : integrate(sage293,sage294,sage295,sage296)$
Maxima ERROR:

rat: replaced -0.0026065763922 by -200/76729 = -.00260657639223762

rat: replaced -11.16 by -279/25 = -11.16

rat: replaced -1.343724 by -3233/2406 = -1.34372402327515

rat: replaced -2.85 by -57/20 = -2.85
Maxima encountered a Lisp error:

 5883790627 is not of type FIXNUM.

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.

However if I shorten the decimals to something like:

integral(integral(e^(-0.0026*(h - 11.1600000000000)^2 - 1.343724*(d - 2.85)^2)/pi, d, 0,Infinity), h, 0, Infinity).n()

Then the command runs fine without any issues. Now perhaps this is a bug, but really I do not need the level of precision that is in these commands. Of course I do not want numbers here but variables and it is evaluating the variables to this level of precision that is causing the issue. For example I say:

sage: f(d,h) = (1/(2*pi*0.61*13.85))*exp(-1/2*((d-2.85)^2/0.61^2+(h-13.85)^2/13.85^2))
sage: f
(h, d) |--> 0.05918210333195241758892111025625850742735*e^(-0.002606576392237615503916381029337017294634*(h - 11.16000000000000000000000000000000000000)^2 - 1.343724805159903251814028486965869389949*(d - 2.850000000000000000000000000000000000000)^2)/pi

Any ideas? P.S. I have searched around, but I have not found any that apply to just basic numbers in Sage.

Preview: (hide)

Comments

Since this appears to be happening entirely in maxima, you might want to ask on the maxima list...

William Stein gravatar imageWilliam Stein ( 14 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 14 years ago

niles gravatar image

Strange, I don't seem to have trouble with

sage: integral(integral(e^(-0.00260657639223762*(h - 11.1600000000000)^2 - 1.34372480515*(d - 2.85000000000000)^2)/pi, d, 0,Infinity), h, 0, Infinity).n()
13.3454645567847

or

sage: f(d,h) = (1/(2*pi*0.61*13.85))*exp(-1/2*((d-2.85)^2/0.61^2+(h-13.85)^2/13.85^2))
sage: integral(integral(f(d,h), d, 0,Infinity), h, 0, Infinity).n()
0.841343497874347

however, the answer to problems with symbolic integration and then numerical evaluating suggests using .n(prec) or RealIntervalField(prec) so, for example, you could try

sage: integral(integral(e^(-0.00260657639223762*(h - 11.1600000000000)^2 - 1.34372480515*(d - 2.85000000000000)^2)/pi, d, 0,Infinity), h, 0, Infinity).n(prec=12)
13.3
sage: integral(integral(f(d,h), d, 0,Infinity), h, 0, Infinity).n(prec=12)
0.842

sage: RealIntervalField(12)(integral(integral(f(d,h), d, 0,Infinity), h, 0, Infinity).n()) 
0.842?
sage: RealIntervalField(30)(integral(integral(f(d,h), d, 0,Infinity), h, 0, Infinity).n()) 
0.841343498?

(does the RealIntervalField(12) answer indicate an error in RealIntervalField() !?)

Preview: (hide)
link

Comments

Hmm... I still get the same error with your options. Perhaps I broke something while trying to fix the problem. Any way to reset everything? Note I tried reset() and it still produced the error.

willmwade gravatar imagewillmwade ( 14 years ago )

I'm afraid the best I could try is quit and restart sage; if you're using the notebook, start a fresh worksheet. If you've already tried these, my next line of defense would be reinstall sage, but you should probably ask a new question here to see if other people have better ideas!

niles gravatar imageniles ( 14 years ago )

I found out how. Deleting ~/.sage did it. rm -Rf ~/.sage

willmwade gravatar imagewillmwade ( 14 years ago )

test comment

Evgeny gravatar imageEvgeny ( 14 years ago )

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: 14 years ago

Seen: 1,320 times

Last updated: Aug 30 '10