0
#plotted log values of Re and C(d)
import numpy as np
import matplotlib.pyplot as plt 
plt.plot([np.log(0.2),np.log(2), np.log(20), np.log(200), np.log(2000), np.log(20000)], [np.log(103), np.log(13.9), np.log(2.72), np.log(0.800), np.log(0.401), np.log(0.433)], 'r-^')
plt.ylabel('C(D)')
plt.xlabel('Re')
plt.show()


#Then we Interpolate
import scipy 
from scipy.interpolate import interpolate
scipy.interpolate.interp1d('x', 'y', kind='cubic')
import matplotlib.pyplot as plt
x = np.linspace[np.log(103), np.log(13.9), np.log(2.72), np.log(0.800), np.log(0.401), np.log(0.433)]
y = [np.log(0.2), np.log(2), np.log(20), np.log(200), np.log(2000), np.log(20000)]
f = interp1d(x, y, kind='cubic')
plt.plot(x, f(x))

So this is my code so far to interpolate a set of data and I have got this far but I am being told that I have a "integer division or modulo by zero" and I have had a play around with it but I cant find my mistake.

darren
  • 47
  • 1
  • 9

1 Answers1

0

This line causes the exception.

scipy.interpolate.interp1d('x', 'y', kind='cubic')

You can look at the traceback and see exactly which line caused the issue. It's doing this because you're giving it strings ('x', 'y') when it wants arrays.

The line f = interp1d(x, y, kind='cubic') is correct, but you're not importing interp1d correctly. You want something like from scipy.interpolate import interp1d or f = scipy.interpolate.interp1d(x, y, kind='cubic').

Doing f(x) is kind of pointless. The whole point of interpolation is to create values other than your input points. As in, points not in the x array.

jpkotta
  • 9,237
  • 3
  • 29
  • 34