Ask Your Question
0

TypeError: unable to simplify to float approximation

asked 2017-11-21 16:13:55 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi, when I try this code on Sage 8.0:

u = var('u'); D = RealDistribution('gaussian',1); f(u) = D.distribution_function(u)

I get the following error message:

TypeError: unable to simplify to float approximation

What I want is to get the numerical approximation of integral_numerical(f(u), u, a, b), for some fixed values a and b.

Thanks.

edit retag flag offensive close merge delete

Comments

Tip: don't tick the "Community wiki" checkbox when posting questions. If it is ticked, upvotes to the question don't earn you karma. You need karma to be able to post links, to upvote questions and answers, etc.

slelievre gravatar imageslelievre ( 2017-11-24 03:54:32 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-11-21 18:19:40 +0100

slelievre gravatar image

No need to define a symbolic variable like u in your example.

The following should be what you want.

sage: D = RealDistribution('gaussian', 1)
sage: f = D.distribution_function
sage: def prob(a, b):
....:     return integral_numerical(f, (a, b))
....: 
sage: prob(1.4, 1.5)
(0.013949457964912993, 1.5487009413687183e-16)

where the output is an estimation of the integral and of the error term in computing it numerically.

edit flag offensive delete link more

Comments

Thanks! Now I want to pass another function into the argument of f, i.e., I want to obtain a numerical approximation of $\int_{a}^{b}f(g(u))\mathrm{d}u$ for some function $g$. How can I do this?

FlacoLearn gravatar imageFlacoLearn ( 2017-11-22 11:04:13 +0100 )edit

You could do the following.

sage: D = RealDistribution('gaussian', 1)
sage: f = D.distribution_function
sage: def prob(a, b):
....:     return integral_numerical(f, (a, b))
....: 
sage: def probg(g, a, b):
....:     return integral_numerical(lambda x: f(g(x)), (a, b))
....: 
sage: g = lambda x: x^2
sage: a, b = 0.7, 0.8
sage: probg(g, a, b)
(0.03401903789457926, 3.7768719146157604e-16)
slelievre gravatar imageslelievre ( 2017-11-24 03:52:29 +0100 )edit

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: 2017-11-21 16:13:55 +0100

Seen: 626 times

Last updated: Nov 21 '17