ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 24 Nov 2017 03:54:32 +0100TypeError: unable to simplify to float approximationhttps://ask.sagemath.org/question/39699/typeerror-unable-to-simplify-to-float-approximation/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.
Tue, 21 Nov 2017 16:13:55 +0100https://ask.sagemath.org/question/39699/typeerror-unable-to-simplify-to-float-approximation/Comment by slelievre for <p>Hi, when I try this code on Sage 8.0:</p>
<p>u = var('u'); D = RealDistribution('gaussian',1); f(u) = D.distribution_function(u)</p>
<p>I get the following error message:</p>
<p>TypeError: unable to simplify to float approximation</p>
<p>What I want is to get the numerical approximation of integral_numerical(f(u), u, a, b), for some fixed values a and b.</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/39699/typeerror-unable-to-simplify-to-float-approximation/?comment=39758#post-id-39758Tip: 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.Fri, 24 Nov 2017 03:54:32 +0100https://ask.sagemath.org/question/39699/typeerror-unable-to-simplify-to-float-approximation/?comment=39758#post-id-39758Answer by slelievre for <p>Hi, when I try this code on Sage 8.0:</p>
<p>u = var('u'); D = RealDistribution('gaussian',1); f(u) = D.distribution_function(u)</p>
<p>I get the following error message:</p>
<p>TypeError: unable to simplify to float approximation</p>
<p>What I want is to get the numerical approximation of integral_numerical(f(u), u, a, b), for some fixed values a and b.</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/39699/typeerror-unable-to-simplify-to-float-approximation/?answer=39705#post-id-39705No 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.Tue, 21 Nov 2017 18:19:40 +0100https://ask.sagemath.org/question/39699/typeerror-unable-to-simplify-to-float-approximation/?answer=39705#post-id-39705Comment by FlacoLearn for <p>No need to define a symbolic variable like <code>u</code> in your example.</p>
<p>The following should be what you want.</p>
<pre><code>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)
</code></pre>
<p>where the output is an estimation of the integral and of the error term
in computing it numerically.</p>
https://ask.sagemath.org/question/39699/typeerror-unable-to-simplify-to-float-approximation/?comment=39720#post-id-39720Thanks! 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?Wed, 22 Nov 2017 11:04:13 +0100https://ask.sagemath.org/question/39699/typeerror-unable-to-simplify-to-float-approximation/?comment=39720#post-id-39720Comment by slelievre for <p>No need to define a symbolic variable like <code>u</code> in your example.</p>
<p>The following should be what you want.</p>
<pre><code>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)
</code></pre>
<p>where the output is an estimation of the integral and of the error term
in computing it numerically.</p>
https://ask.sagemath.org/question/39699/typeerror-unable-to-simplify-to-float-approximation/?comment=39757#post-id-39757You 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)Fri, 24 Nov 2017 03:52:29 +0100https://ask.sagemath.org/question/39699/typeerror-unable-to-simplify-to-float-approximation/?comment=39757#post-id-39757