user1387717
user1387717

Reputation: 1049

scipy.interpolate.splrep giving incorrect interpolation for b-spline

I'm using the following code:

x = [80, 85, 90, 95, 100, 105, 110, 115]
y = [0.31976258043267208, 0.31718670335264199, 0.30116311412953689, 0.29687766899837931, 0.29802720516866577, 0.30707962224836099, 0.32328422706655086, 0.34467623793716823]

bSpline = scipy.interpolate.splrep(x, y, k=3)
yInterp = scipy.interpolate.splev(np.linspace(0,1,num=8), bSpline)

but the bSpline has weird knots (some are 0) and then the yInterp is all messed up:

 bSpline: (array([  80,   80,   80,   80,   90,   95,  100,  105,  115, 115,  115,  115 ]), array([ 0.31976258,  0.33015199,  0.29797999,  0.29680536,  0.29635823,
    0.30911387,  0.32907255,  0.34467624,  0,  0, 0,  0 ]), 3)
 yInterp: [-29.46356522 -29.3160613  -29.16904367 -29.02251153 -28.87646408, -28.73090053 -28.58582008 -28.44122191]

yInterp should have some values around positive 0.30 not -28 and -29

Upvotes: 1

Views: 502

Answers (1)

Warren Weckesser
Warren Weckesser

Reputation: 114966

The x values that you passed to splrep range from 80 to 115. You are evaluating the spline at values ranging from 0 to 1. If you evaluate at values within the input range, the output will be around 0.3.

Upvotes: 2

Related Questions