问题
I have some scattered 1-d data sets and I want to interpolate with rbf function by using scipy.interpolate.Rbf function. However, for a specific set of data it seems that the interpolation fails giving LinAlgError: singular matrix error. The x-y data are:
x = numpy.array([169., 161., 153., 146., 139., 134., 129., 127., 123.,
121., 119., 120., 119., 121., 124., 125., 128., 133.,
137., 141., 143.]])
y = numpy.array([415., 407., 398., 390., 380., 371., 361., 352., 342.,
333., 321., 313., 304., 296., 286., 277., 268., 259.,
250., 244., 239.])
rbf = interpolate.Rbf(x, y, function='cubic',smooth=0.)
Traceback (most recent call last):
File "<ipython-input-10-ddb099423b50>", line 1, in <module>
rbf = interpolate.Rbf(x, y, function='cubic',smooth=0.)
File "C:\WinPython-32bit-2.7.5.3\python-2.7.5\lib\site-packages\scipy\interpolate\rbf.py", line 207, in __init__
self.nodes = linalg.solve(self.A, self.di)
File "C:\WinPython-32bit-2.7.5.3\python-2.7.5\lib\site-packages\scipy\linalg\basic.py", line 100, in solve
raise LinAlgError("singular matrix")
LinAlgError: singular matrix
How could I avoid this error? Is it because my data points are very close to one another and the Gram matrix cannot be inverted? How could I interpolate these data?
Thanks a lot in advance.
回答1:
As @moarningsun has already pointed out, every x-value must not equal any other x-value.
The same holds for multidimensional data. No n-dimensional sampling point (i.e. data location point) may appear twice.
来源:https://stackoverflow.com/questions/27295853/rbf-interpolation-fails-linalgerror-singular-matrix