Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

TypeError: unable to simplify to float approximation

asked 7 years ago

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.

Preview: (hide)

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 ( 7 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 7 years ago

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.

Preview: (hide)
link

Comments

Thanks! Now I want to pass another function into the argument of f, i.e., I want to obtain a numerical approximation of baf(g(u))du for some function g. How can I do this?

FlacoLearn gravatar imageFlacoLearn ( 7 years ago )

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

Seen: 640 times

Last updated: Nov 21 '17