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.Thu, 03 Jan 2019 21:49:02 +0100TypeError 'unable to simplify to float approximation' while trying to define an integral operatorhttps://ask.sagemath.org/question/44805/typeerror-unable-to-simplify-to-float-approximation-while-trying-to-define-an-integral-operator/ Hello, I am trying to define an integral operator acting on a subspace of $L^2(\mathbb{R})$ that depends of time using sage. Being more explicit $W(t)$ takes a real function $f$ and returns another function $g$ defined by
\begin{equation}
W(t)f(x)=g(x)=\int_{-\infty}^{+\infty}K(x,y,z)f(y)\text{d}y
\end{equation}
This is the code I came up with
def W(t):
def dummy2(f):
def dummy3(x):
integrand(y)=f(y)*K(x,y,t)
return numerical_integral(integrand,-Infinity,+Infinity,algorithm='qag')[0]
return dummy3
return dummy2
With $K$ a reasonable function of $x,y,t$
However I am getting the following error
TypeError: unable to simplify to float approximation
I am pretty sure it's related to the types passed to numerical_integrand
What could be a solution? Or a better way to implement it?
Thank you allSat, 29 Dec 2018 22:37:22 +0100https://ask.sagemath.org/question/44805/typeerror-unable-to-simplify-to-float-approximation-while-trying-to-define-an-integral-operator/Comment by rburing for <p>Hello, I am trying to define an integral operator acting on a subspace of $L^2(\mathbb{R})$ that depends of time using sage. Being more explicit $W(t)$ takes a real function $f$ and returns another function $g$ defined by
\begin{equation}
W(t)f(x)=g(x)=\int_{-\infty}^{+\infty}K(x,y,z)f(y)\text{d}y
\end{equation}
This is the code I came up with</p>
<pre><code>def W(t):
def dummy2(f):
def dummy3(x):
integrand(y)=f(y)*K(x,y,t)
return numerical_integral(integrand,-Infinity,+Infinity,algorithm='qag')[0]
return dummy3
return dummy2
</code></pre>
<p>With $K$ a reasonable function of $x,y,t$
However I am getting the following error</p>
<pre><code>TypeError: unable to simplify to float approximation
</code></pre>
<p>I am pretty sure it's related to the types passed to numerical_integrand
What could be a solution? Or a better way to implement it?
Thank you all</p>
https://ask.sagemath.org/question/44805/typeerror-unable-to-simplify-to-float-approximation-while-trying-to-define-an-integral-operator/?comment=44810#post-id-44810The code looks fine. (Maybe change to `integrand = lambda y: f(y)*K(x,y,t)`). What is the function $K$ and the call that yields the error? Note $K$ must return a constant which has a floating point approximation, and hence cannot contain symbolic variables (though you could work around this by considering them as formal variables).Sun, 30 Dec 2018 13:55:28 +0100https://ask.sagemath.org/question/44805/typeerror-unable-to-simplify-to-float-approximation-while-trying-to-define-an-integral-operator/?comment=44810#post-id-44810Comment by guesswhowhere for <p>Hello, I am trying to define an integral operator acting on a subspace of $L^2(\mathbb{R})$ that depends of time using sage. Being more explicit $W(t)$ takes a real function $f$ and returns another function $g$ defined by
\begin{equation}
W(t)f(x)=g(x)=\int_{-\infty}^{+\infty}K(x,y,z)f(y)\text{d}y
\end{equation}
This is the code I came up with</p>
<pre><code>def W(t):
def dummy2(f):
def dummy3(x):
integrand(y)=f(y)*K(x,y,t)
return numerical_integral(integrand,-Infinity,+Infinity,algorithm='qag')[0]
return dummy3
return dummy2
</code></pre>
<p>With $K$ a reasonable function of $x,y,t$
However I am getting the following error</p>
<pre><code>TypeError: unable to simplify to float approximation
</code></pre>
<p>I am pretty sure it's related to the types passed to numerical_integrand
What could be a solution? Or a better way to implement it?
Thank you all</p>
https://ask.sagemath.org/question/44805/typeerror-unable-to-simplify-to-float-approximation-while-trying-to-define-an-integral-operator/?comment=44877#post-id-44877I still get an error, I defined K as
K(x,y,t)=1/(x^2+y^2+t^2+1)
How can I define them as formal variables?Thu, 03 Jan 2019 21:04:34 +0100https://ask.sagemath.org/question/44805/typeerror-unable-to-simplify-to-float-approximation-while-trying-to-define-an-integral-operator/?comment=44877#post-id-44877Answer by rburing for <p>Hello, I am trying to define an integral operator acting on a subspace of $L^2(\mathbb{R})$ that depends of time using sage. Being more explicit $W(t)$ takes a real function $f$ and returns another function $g$ defined by
\begin{equation}
W(t)f(x)=g(x)=\int_{-\infty}^{+\infty}K(x,y,z)f(y)\text{d}y
\end{equation}
This is the code I came up with</p>
<pre><code>def W(t):
def dummy2(f):
def dummy3(x):
integrand(y)=f(y)*K(x,y,t)
return numerical_integral(integrand,-Infinity,+Infinity,algorithm='qag')[0]
return dummy3
return dummy2
</code></pre>
<p>With $K$ a reasonable function of $x,y,t$
However I am getting the following error</p>
<pre><code>TypeError: unable to simplify to float approximation
</code></pre>
<p>I am pretty sure it's related to the types passed to numerical_integrand
What could be a solution? Or a better way to implement it?
Thank you all</p>
https://ask.sagemath.org/question/44805/typeerror-unable-to-simplify-to-float-approximation-while-trying-to-define-an-integral-operator/?answer=44878#post-id-44878You don't have to define any formal variables in that case. You still haven't specified what call is giving you an error. An example of a correct call is `W(0)(lambda x: 1)(1)` (here $t=0, f(x) = 1, x = 1$) which gives the result without error.Thu, 03 Jan 2019 21:49:02 +0100https://ask.sagemath.org/question/44805/typeerror-unable-to-simplify-to-float-approximation-while-trying-to-define-an-integral-operator/?answer=44878#post-id-44878