0

New coder here. I have 2 rows of inputs and 3 of outputs, trying to interpolate between the inputs. The outputs are experimentally determined coefficients. The input data does form a grid.

Inputs are temperature, %concentration. Outputs are coefficients A, B, C.

T      %
[[316, 3],
 [316, 6],
 [322, 3],
 [322, 6],
 [333, 3],
 [333, 6]]
A, B, C
[[0.2925*10**-11, 7517.9, -0.0027],
 [0.1275*10**-14, 9826.53, -0.0471], 
 [0.2506*10**-13, 8923.77, -0.0010],
 [0.2506*10**-15, 10669.89, -0.2284],
 [0.7319*10**-10, 6770.42, -0.0467],
 [0.1800*10**-13, 9259.93, -0.0564]]

I've tried multidimensional linear interpolation using numpy and scipy.linalg as taught in class but I think it only works for data with known functions. The columns of the square matrix are [1], T, %, T*%, T/%, %/T. I figured it only works with a square matrix but I'm still not getting good values. This one just tries to solve for the coefficient A for the moment.

import numpy
import scipy.linalg
N = 6
coorA = numpy.zeros((N,N))
coorA = [[1, 316, 3, 948, 105, 0.0095],
         [1, 316, 6, 1896, 53, 0.0190],
         [1, 322, 3, 966, 107, 0.0093],
         [1, 322, 6, 1932, 54, 0.0186],
         [1, 333, 3, 999, 111, 0.0090],
         [1, 333, 6, 1998, 56, 0.0180]]
solnA = numpy.zeros(N)
solnA = [0.2925*10**-11, 0.1275*10**-14, 0.2506*10**-13, 0.2691*10**-15, 0.7319*10**-10, 0.18*10**-13]
cA = numpy.zeros(N)
cA = scipy.linalg.solve(coorA, solnA)
x = 316
y = 6
A = cA[0] + cA[1]*x + cA[2]*y + cA[3]*x*y + cA[4]*x/y + cA[5]/x*y
print (coorA)
print (solnA)
print (cA)
print (A)
# A output was -9.966296504331275e-11
# A output should be 0.1275*10**-14 as it's the 2nd line of inputs

Any idea on how to move forward? I feel like there's an easy answer but this class is a crash course into coding.

1 Answers1

0

Interpolation should work with unknown functions, that's why you interpolate. If the functions were known, you would be fitting them to the data.

I'd suggest that you take a look at scipy.interpolate.interp2d as shown here. Each of your output is a function of two variables (the inputs) so I would do 3 of these 2D interpolations, for each output variable independently.

Botond
  • 2,640
  • 6
  • 28
  • 44
  • from what I read on that link, I have to use np.arange which does not allow me to use data which forms a grid, as each of the values in the input arrays appears twice in the data. Also the Z-values are not evenly spaced so I cannot use an array for them either. – PSchexy94 Nov 16 '20 at 18:56