New ScreenPanel
This commit is contained in:
37
script/test21.py
Executable file
37
script/test21.py
Executable file
@@ -0,0 +1,37 @@
|
||||
from mathutils import *
|
||||
|
||||
#interpolation
|
||||
y = [0, 1, 4,10,50,25,12, 5, 3, 0]
|
||||
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
types = "linear", "cubic", "akima", "loess", "neville", "newton"
|
||||
functions = [interpolate(y,x,t) for t in types]
|
||||
|
||||
plot_x = frange (0,9,0.01)
|
||||
values = [get_values(f,plot_x) for f in functions]
|
||||
plots=plot(values,types,plot_x)
|
||||
|
||||
#derivative
|
||||
for i in range(len(types)):
|
||||
try:
|
||||
d = deriv(functions[i])
|
||||
plots[i].addSeries(LinePlotSeries("Derivative"))
|
||||
plots[i].getSeries(1).setData(plot_x, get_values(d,plot_x))
|
||||
except:
|
||||
#not differentiable
|
||||
pass
|
||||
|
||||
#integration
|
||||
for i in range(len(types)):
|
||||
s = integrate(functions[i],x)
|
||||
plots[i].addMarker(x[-1], None, "Integral=" + str(round(s,4)), java.awt.Color.DARK_GRAY)
|
||||
|
||||
|
||||
|
||||
|
||||
#Direct calculation on arrays:
|
||||
|
||||
print "Deriv (linear interpolation): ", deriv(y,x)
|
||||
print "Deriv (cubic interpolation): ", deriv(y, x, "cubic")
|
||||
print "Integral (linear interpolation): ", integrate(y, None, x, "cubic")
|
||||
print "Integral (cubic interpolation): ", integrate(y, None, x, "cubic")
|
||||
print "Integral (linear interpolation in range [1,5]): ", integrate(y, [1,5], x)
|
||||
Reference in New Issue
Block a user