三次样条插值(Python实现)

本文介绍了如何使用Python的pandas和SciPy库进行三次样条插值,并展示了在Threemomentmethod.xlsx数据集上的应用实例。同时,作者强调了系统化学习的重要性,推荐了一套免费的学习资源供读者参考和参与技术交流社群。
摘要由CSDN通过智能技术生成

import pandas as pd

import matplotlib.pyplot as plt

from scipy import interpolate

import matplotlib as mpl

mpl.rcParams[“font.sans-serif”] = [“SimHei”]

mpl.rcParams[“axes.unicode_minus”] = False

Import data

file = pd.read_excel(‘Three moment method.xlsx’,header=None,names=[‘x’, ‘value’])

data = pd.DataFrame(file)

数组切片

x = data[‘x’] # Take the first column of data

y = data[‘value’] # Take the second column of data

Spline interpolation of correlation functions in SciPy Library

tck = interpolate.splrep(x, y) #(t,c,k)包含节点向量、B样条曲线系数和样条曲线阶数的元组。

xx = np.linspace(min(x), max(x), 200)

yy = interpolate.splev(xx, tck, der=0)

x1,x2=-0.02,2.56

y1=interpolate.splev(x1,tck,der=0)

y2=interpolate.splev(x2,tck,der=0)

print(‘When x = -0.02, the value of Y is:’,y1)

print(‘When x = 2.56, the value of Y is:’,y2)

print(yy)

plt.plot(x, y,‘ro’, xx, yy ,‘b’)

plt.legend([‘true’, ‘cubic spline’])

plt.xlabel(‘X’)

plt.ylabel(‘Y’)

plt.grid(True)

plt.title(‘Three moment method of cubic spline interpolation’)

Save picture

plt.savefig(‘out2.png’, dpi=600)

Set the resolution at which you want to save the picture

plt.show()

[注] 1、pd.DataFrame()函数2、SciPy interpolate(插值)

4、结果


When x = -0.02, the value of Y is: -2.7618446933498895

When x = 2.56, the value of Y is: 4.73015581306341

[-2.46000000e+00 -2.78641445e+00 -3.08977770e+00 -3.37066746e+00

-3.62966147e+00 -3.86733746e+00 -4.08427316e+00 -4.28104630e+00

-4.45823461e+00 -4.61641582e+00 -4.75616766e+00 -4.87806786e+00

-4.98269414e+00 -5.07062425e+00 -5.14243590e+00 -5.19870684e+00

-5.24001478e+00 -5.26693746e+00 -5.28005262e+00 -5.27993797e+00

-5.26717125e+00 -5.24233019e+00 -5.20599252e+00 -5.15873597e+00

-5.10113827e+00 -5.03377715e+00 -4.95723034e+00 -4.87207557e+00

-4.77889057e+00 -4.67825307e+00 -4.57074080e+00 -4.45693149e+00

-4.33740287e+00 -4.21273266e+00 -4.08349861e+00 -3.95027844e+00

-3.81364988e+00 -3.67419066e+00 -3.53247850e+00 -3.38909115e+00

-3.24460633e+00 -3.09960177e+00 -2.95465520e+00 -2.81034434e+00

-2.66724694e+00 -2.52594072e+00 -2.38700341e+00 -2.25101274e+00

-2.11854644e+00 -1.99018224e+00 -1.86649786e+00 -1.74794500e+00

-1.63451294e+00 -1.52608502e+00 -1.42254454e+00 -1.32377483e+00

-1.22965918e+00 -1.14008093e+00 -1.05492338e+00 -9.74069856e-01

-8.97403663e-01 -8.24808121e-01 -7.56166544e-01 -6.91362247e-01

-6.30278546e-01 -5.72798756e-01 -5.18806191e-01 -4.68184167e-01

-4.20815999e-01 -3.76585002e-01 -3.35374491e-01 -2.97067781e-01

-2.61548188e-01 -2.28699025e-01 -1.98403609e-01 -1.70545255e-01

-1.45007277e-01 -1.21672990e-01 -1.00425711e-01 -8.11487529e-02

-6.37254319e-02 -4.80390629e-02 -3.39729610e-02 -2.14104413e-02

-1.02348187e-02 -3.29408529e-04 8.42247428e-03 1.61375146e-02

2.29323974e-02 2.89238074e-02 3.42284298e-02 3.89629493e-02

4.32440509e-02 4.71884195e-02 5.09130460e-02 5.45723558e-02

5.83936999e-02 6.26128392e-02 6.74655344e-02 7.31875464e-02

8.00146360e-02 8.81825640e-02 9.79270913e-02 1.09483979e-01

1.23088987e-01 1.38977877e-01 1.57386409e-01 1.78550345e-01

2.02705445e-01 2.30087470e-01 2.60932180e-01 2.95475338e-01

现在能在网上找到很多很多的学习资源,有免费的也有收费的,当我拿到1套比较全的学习资源之前,我并没着急去看第1节,我而是去审视这套资源是否值得学习,有时候也会去问一些学长的意见,如果可以之后,我会对这套学习资源做1个学习计划,我的学习计划主要包括规划图和学习进度表。

分享给大家这份我薅到的免费视频资料,质量还不错,大家可以跟着学习

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里无偿获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 10
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值