Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I have put something together but I think there might be better solutions:

from sage.gsl.all import spline
values = [(-3,-2),(-2,0),(1,2),(3,1),(4,5)]
interpolation = spline(values)
import scipy as sp
var('x')
f = lambda x: sp.derivative(interpolation,x)
F = lambda x: numerical_integral(interpolation,-3,x)[0]
plot(interpolation,(-3,5)) + list_plot(values) + plot(f,(-3,5),color='red') + plot(F,(-3,5),color='green')

output

local_maximum = plot(interpolation,(-4,3)).ymax()
print('local maximum ' + str((local_maximum,interpolation(local_maximum))))
print('root ' + str(find_root(interpolation,-3,4)))

Output:

local maximum (2.4229598692250027, 0.39016552466712007)
root -2.0

I have put something together but I think there might be better solutions:

from sage.gsl.all import spline
values = [(-3,-2),(-2,0),(1,2),(3,1),(4,5)]
interpolation = spline(values)
import scipy as sp
var('x')
f = lambda x: sp.derivative(interpolation,x)
F = lambda x: numerical_integral(interpolation,-3,x)[0]
plot(interpolation,(-3,5)) + list_plot(values) + plot(f,(-3,5),color='red') + plot(F,(-3,5),color='green')

output

local_maximum = plot(interpolation,(-4,3)).ymax()
print('local maximum ' + str((local_maximum,interpolation(local_maximum))))
str(local_maximum))
print('root ' + str(find_root(interpolation,-3,4)))

Output:

local maximum (2.4229598692250027, 0.39016552466712007)
2.4229598692250027
root -2.0

However this way I don't get the x value of my local maximum.