不同插值对比

数据Tb(v)

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from scipy.interpolate import interp1d
plt.style.use('https://gitee.com/Astro-Lee/storage/raw/master/mystyle.mplstyle')

info = pd.read_csv('https://gitee.com/Astro-Lee/storage/raw/master/data/Tb(v)_data.csv')
Tb = np.array(info['Tb'])
v = np.array(info['v'])

kind = ['nearest','zero','slinear','linear','quadratic','cubic']

u = np.linspace(v[240],v[252],100)
fig = plt.figure(figsize=(16,8),dpi=300)

axes = fig.subplots(2,3,sharex = True,sharey = True)
ax = axes.ravel()

for i,kd in enumerate(kind):
    ax[i].plot(v[240:252+1],Tb[240:252+1],'o',mec='k',mfc='w',ms=3)
    f = interp1d(v[240:252+1],Tb[240:252+1],kind=kd)
    value = f(u)
    ax[i].plot(u,value,'b',label=kd)
    ax[i].legend()
    ax[i].set_xlabel('$v\mathrm{(km/s)}$')
    ax[i].set_ylabel('$T_b\mathrm{(K)}$')
fig.savefig('interp.png')

在这里插入图片描述

Gaussian-Legendre integral

#对cubic插值进行积分
from scipy.special import roots_legendre

N = 20                #取样本点个数
a, b = v[240], v[252]   #积分上下限

x, wi = roots_legendre(N)
xi = x*(b-a)/2 + (b+a)/2

s = (b-a)/2 * np.dot(wi, f(xi))
print('积分值:',s)

积分值: 6923.791421843061

Simpson integral

from scipy.integrate import simpson

print('积分值:',simpson(Tb[240:252+1],v[240:252+1]))

积分值: 6883.528256826916

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值