# TypeError: unable to simplify to float approximation 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 close merge delete

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.

Sort by » oldest newest most voted

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.

more

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?

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)