具有四个一维数组的 3d 曲线拟合

问题描述 投票:0回答:0

我想将我的数据拟合到一个函数中,但我不知道如何使用 scipy 曲线拟合来获取拟合参数。

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
from scipy.optimize import curve_fit
import scipy.interpolate

def bi_func(x, y, v, alp, bta, A):
    return A * np.exp(-((x-v)/alp)**2-(y/bta)**2)


def log_tick_formatter(val, pos=None):
    return f"$10^{{{val}}}$"  


xmin, xmax, nx = -9289.34, 9668.51, 51
ymin, ymax, ny = -9289.34, 9668.51, 51
x, y = np.linspace(xmin, xmax, nx), np.linspace(ymin, ymax, ny)
X, Y = np.meshgrid(x, y)

z1min, z1max, nz1 = 4e-15,5.76e-11, 51
z2min, z2max, nz2 = 1.29e-14, 5.68e-11, 51
z1, z2 = np.linspace(z1min, z1max, nz1), np.linspace(z2min, z2max, nz2)
rbf = scipy.interpolate.Rbf(x, z1, z2)
Z=rbf(X,Y)

p0 = [(0, 20, 18, 5.4),
         (0, 4, 6, 2.5, 1.8),
         (0, 190, 150, 2),
         (0, 100, 70, 1, 5)
        ]

fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.plot_surface(X, Y, Z, cmap='viridis')
ax.set_zlim(np.min(Z),np.max(Z))
ax.zaxis.set_major_formatter(mticker.FuncFormatter(log_tick_formatter))
plt.show()
   
xdata = np.vstack((x, y))
zdata = np.vstack((z1,z2))
popt, pcov = curve_fit(bi_func, xdata, zdata, p0=p0)
#And plot the results:


我尝试将我的四个一维数组数据拟合到一个函数中,但我无法找到拟合参数。

scipy curve-fitting contour data-fitting
© www.soinside.com 2019 - 2024. All rights reserved.