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.Wed, 28 Mar 2012 22:07:51 +0200Plotting an integral with a variable as a limithttps://ask.sagemath.org/question/8820/plotting-an-integral-with-a-variable-as-a-limit/I want to plot a function with a variable as a limit, e.g. look at \int_0^x f(y) d y, but this seems to throw an error when Sage can't analytically integrate the function.
x,y=var('x y')
f(y)=integrate(x^x,x,1,y)
plot(f,2,10)
Returns
Traceback (click to the left of this block for traceback)
...
ValueError: free variable: x
Can anybody help with this, please? Many thanks.Wed, 28 Mar 2012 17:52:02 +0200https://ask.sagemath.org/question/8820/plotting-an-integral-with-a-variable-as-a-limit/Answer by kcrisman for <p>I want to plot a function with a variable as a limit, e.g. look at \int_0^x f(y) d y, but this seems to throw an error when Sage can't analytically integrate the function.</p>
<pre><code>x,y=var('x y')
f(y)=integrate(x^x,x,1,y)
plot(f,2,10)
</code></pre>
<p>Returns </p>
<pre><code>Traceback (click to the left of this block for traceback)
...
ValueError: free variable: x
</code></pre>
<p>Can anybody help with this, please? Many thanks.</p>
https://ask.sagemath.org/question/8820/plotting-an-integral-with-a-variable-as-a-limit/?answer=13402#post-id-13402The following is only a workaround, and it likely extremely slow.
sage: f(y) = integrate(x^x,x,1,y)
sage: plot(lambda y: f(y), (y,2,10))
You can see that it's slow because even
sage: plot(lambda y: f(y), (y,2,10),plot_points=10,adaptive_recursion=2)
is really slow.
If you give up on symbolic stuff, though, then
sage: plot(lambda y: numerical_integral(x^x,1,y)[0],(y,2,10))
is a good substitute. Notice that we probably still will need the lambda solution, or to define a Python function.Wed, 28 Mar 2012 22:07:51 +0200https://ask.sagemath.org/question/8820/plotting-an-integral-with-a-variable-as-a-limit/?answer=13402#post-id-13402