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.Tue, 18 Sep 2012 09:27:06 +0200how to find root of a splinehttps://ask.sagemath.org/question/9329/how-to-find-root-of-a-spline/Basicaly the title says it: I have data points for which i need to find the x value where y is a known value. I tried it like this, but it seems that it should be done differently:
from sage.gsl.all import spline
data=[[0,1],[1,2],[2,2.2],[3,2.4],[4,0.4],[5,0.1],[6,-0.5]]
func=spline(data)
x=var('x')
find_root(func(x),0,6)
..[Error message with main idea - TypeError: unable to simplify to float approximation]Tue, 18 Sep 2012 04:41:52 +0200https://ask.sagemath.org/question/9329/how-to-find-root-of-a-spline/Answer by achrzesz for <p>Basicaly the title says it: I have data points for which i need to find the x value where y is a known value. I tried it like this, but it seems that it should be done differently:</p>
<pre><code>from sage.gsl.all import spline
data=[[0,1],[1,2],[2,2.2],[3,2.4],[4,0.4],[5,0.1],[6,-0.5]]
func=spline(data)
x=var('x')
find_root(func(x),0,6)
..[Error message with main idea - TypeError: unable to simplify to float approximation]
</code></pre>
https://ask.sagemath.org/question/9329/how-to-find-root-of-a-spline/?answer=14043#post-id-14043 sage: find_root(func,0,6)
5.3157137464283455
sage: plot(func,[x,0,6])Tue, 18 Sep 2012 05:48:58 +0200https://ask.sagemath.org/question/9329/how-to-find-root-of-a-spline/?answer=14043#post-id-14043Comment by kcrisman for <pre><code>sage: find_root(func,0,6)
5.3157137464283455
sage: plot(func,[x,0,6])
</code></pre>
https://ask.sagemath.org/question/9329/how-to-find-root-of-a-spline/?comment=19047#post-id-19047Just to elaborate, when you did `func(x)`, you wanted Sage to evaluate the spline at the symbolic variable `x`. But our splines aren't (yet) symbolic, so it raised an error because it wanted an actual numeric input.Tue, 18 Sep 2012 09:27:06 +0200https://ask.sagemath.org/question/9329/how-to-find-root-of-a-spline/?comment=19047#post-id-19047