cubic-spline

Cubic spline interpolation get coefficients

ε祈祈猫儿з 提交于 2019-12-11 04:58:13
问题 Say I have two arrays in python and I wish to get (and actually use) the cubic spline interpolation between those points. (IE: I wish to integrate the function). I would strongly prefer a way using numpy scipy. I know about scipy.interpolate.interp1d. However that only allows me to evalute the points, for say the very simply function of: Now I could do something simply like: import numpy as np import scipy.interpolate import matplotlib.pyplot as plt y = np.array([0,2,3,4,8,10,12,12,12,10,9,8

How to perform cubic spline interpolation in python?

China☆狼群 提交于 2019-12-02 18:25:35
I have two lists to describe the function y(x): x = [0,1,2,3,4,5] y = [12,14,22,39,58,77] I would like to perform cubic spline interpolation so that given some value u in the domain of x, e.g. u = 1.25 I can find y(u). I found this in SciPy but I am not sure how to use it. youngmit Short answer: from scipy import interpolate def f(x): x_points = [ 0, 1, 2, 3, 4, 5] y_points = [12,14,22,39,58,77] tck = interpolate.splrep(x_points, y_points) return interpolate.splev(x, tck) print(f(1.25)) Long answer: scipy separates the steps involved in spline interpolation into two operations, most likely for

What algorithm used in interp1d function in scipy.interpolate

我的梦境 提交于 2019-12-02 09:43:42
问题 So i was writing a python program for my numerical course, and I had to code a cubic spline program. So i implement the formula for cubic spline given in books like Numerical methods by Chapra and canale and Numerical mathematics by chenny and kincaid. so my data is x=[1.0,3.0,4.0,7.0] y=[1.5,4.5,9.0,25.5] Using this data and applying cubic spline I get for x=1.5 , y=1.79122340426 While using this same data but using the scipy function gives: >>> scipy.interpolate.interp1d(x, y, kind='cubic')

Calculate a 2D spline curve in R

蹲街弑〆低调 提交于 2019-12-01 03:17:50
I'm trying to calculate a Bezier-like spline curve that passes through a sequence of x-y coordinates. An example would be like the following output from the cscvn function in Matlab ( example link ): I believe the (no longer maintained) grid package used to do this ( grid.xspline function?), but I haven't been able to install an archived version of the package, and don't find any examples exactly along the lines of what I would like. The bezier package also looks promising, but it is very slow and I also can't get it quite right: library(bezier) set.seed(1) n <- 10 x <- runif(n) y <- runif(n)

Calculate a 2D spline curve in R

我只是一个虾纸丫 提交于 2019-11-30 23:49:02
问题 I'm trying to calculate a Bezier-like spline curve that passes through a sequence of x-y coordinates. An example would be like the following output from the cscvn function in Matlab (example link): I believe the (no longer maintained) grid package used to do this ( grid.xspline function?), but I haven't been able to install an archived version of the package, and don't find any examples exactly along the lines of what I would like. The bezier package also looks promising, but it is very slow

Cubic spline interpolation vs polynomial interpolation

瘦欲@ 提交于 2019-11-28 13:01:21
I am asked to investigate the different types of interpolation using Matlab for the following points: x = [32 34 35 36 37 38] y = [26 28 31 30 29 25] and find the values for f(33) , f(33.5) and f(35) . When plotting x and y, I can see that f(33) should be around 27, which is also what I get using interp1(x,y,33) . I am not sure if this is the correct way of using the Cubic spline interpolation function but I used spline(x,y,33) and got ans = 24.3906 . Shouldn't I still get the same value for f(33) no matter what type of interpolation I use? Interpolation makes sure the values of the

Cubic spline interpolation vs polynomial interpolation

狂风中的少年 提交于 2019-11-27 07:28:24
问题 I am asked to investigate the different types of interpolation using Matlab for the following points: x = [32 34 35 36 37 38] y = [26 28 31 30 29 25] and find the values for f(33) , f(33.5) and f(35) . When plotting x and y, I can see that f(33) should be around 27, which is also what I get using interp1(x,y,33) . I am not sure if this is the correct way of using the Cubic spline interpolation function but I used spline(x,y,33) and got ans = 24.3906 . Shouldn't I still get the same value for