Paraboloid (3D parabola) surface fitting python

天涯浪子 提交于 2019-12-19 03:43:51

问题


I am trying to fit this x data: [0.4,0.165,0.165,0.585,0.585], this y data: [.45, .22, .63, .22, .63], and this z data: [1, 0.99, 0.98,0.97,0.96] to a paraboloid. I am using scipy's curve_fit tool. Here is my code:

doex = [0.4,0.165,0.165,0.585,0.585]
doey = [.45, .22, .63, .22, .63]
doez = np.array([1, .99, .98,.97,.96])

def paraBolEqn(data,a,b,c,d):
    if b < .16 or b > .58  or c < .22 or c >.63:
        return 1e6
    else:
        return ((data[0,:]-b)**2/(a**2)+(data[1,:]-c)**2/(a**2))

data = np.vstack((doex,doey))
zdata = doez

opt.curve_fit(paraBolEqn,data,zdata)

I am trying to center the paraboloid between .16 and .58 (x axis) and between .22 and .63 (y axis). I am doing this by returning a large value if b or c are outside of this range.

Unfortunately the fit is wayyy off and my popt values are all 1, and my pcov is inf.

Any help would be great.

Thank you


回答1:


Rather than forcing high return values for out-of range regions you need to provide a good initial guess. In addition, the mode lacks an offset parameter and the paraboloid has the wrong sign. Change the model to:

def paraBolEqn(data,a,b,c,d):
    x,y = data
    return -(((x-b)/a)**2+((y-d)/c)**2)+1.0

I fixed the offset to 1.0 because if it were added as fit parameter the system would be underdetermined (fewer or equal number of data points than fit parameters). Call curve_fit with an initial guess like this:

popt,pcov=opt.curve_fit(paraBolEqn,np.vstack((doex,doey)),doez,p0=[1.5,0.4,1.5,0.4])

This yields:

[ 1.68293045  0.31074135  2.38822062  0.36205424]

and a nice nice match to the data:



来源:https://stackoverflow.com/questions/26152222/paraboloid-3d-parabola-surface-fitting-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!