简体   繁体   中英

Curve fitting and Extrapolation for 3d plot in python

I want to extrapolate 3d plot in python using numpy/scipy. Extrapolation is done with curve fitting. Refer to the following data which is having different x & y sizes.

x = np.array([740,760,780,800,820,840,860,880,900,920,940,960])     # Presssure in mBar

y = np.array([1500,1800,2100,2400,2700,3000,3300,3600,3900])     # Rpm

# Fuel Amount in micro seconds

z = np.array([[1820,1820,1820,1820,2350,2820,3200,3440,3520,3600,3600,3600],  
              [1930,1930,1930,2170,2700,2880,3240,3580,3990,3990,3990,3990],  
              [1900,1900,2370,2680,2730,3050,3450,3760,3970,3970,3970,3970],  
              [2090,2090,2240,2410,2875,3180,3410,3935,4270,4270,4270,4270],  
              [1600,2180,2400,2700,2950,3290,3780,4180,4470,4470,4470,4470],  
              [2100,2280,2600,2880,3320,3640,4150,4550,4550,4550,4550,4550],  
              [2300,2460,2810,3170,3400,3900,4280,4760,4760,4760,4760,4760],  
              [2170,2740,3030,3250,3600,4100,4370,4370,4370,4370,4370,4370],  
             [2240,2580,2870,3275,3640,4050,4260,4260,4260,4260,4260,4260]])

Scipy has scipy.interpolate.interp2d class but it only interpolates if x & y are of same size. http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.interp2d.html

I want to extrapolate the curve at y axis points 900 & 1200 & at x axis point 720.

ie

xNew = (720,x)
yNew = (900,1200,y)

Since I don't have the function in terms of z = f(x,y). How curve fitting can be done in python for above case and get the curve values at required points.

You need to provide the grid on which your z values are constructed, ie something like

x=[[740,760,...,960],
   .....
   [740,760,...,960]]

and similarly for y . This can be achieved using numpy.meshgrid :

xx,yy=np.meshgrid(x,y)
test_function=interp2d(xx,yy,z)

Using your data, I can execute test_function(720,900) and get a value of 1820, which is nearest neighbour extrapolation. If you need "better" extrapolation (whatever that means), you need to develop some kind of model function for your data and use the fitting methods inside scipy .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM