Here is my code,
import numpy as np
import math
import matplotlib.pyplot as plt
#Voltages
V,I = np.genfromtxt('Photocurrent_graph_2.csv', dtype=float, delimiter=',',
usecols=(0,2), skiprows=1, unpack=True)
z = np.polyfit(V,I,6)
def function(x):
return (z[0])*x**6 (z[1])*x**5 + (z[2])*x**4 + (z[3])*x**3 + (z[4])*x**2 + (z[6])*x + z[7]
plt.plot(V, function(V))
plt.plot(V,I,'ro')
If I comment out the line plt.plot(V, function(V)), python does not give me any errors. What have I done wrong?
EDIT:
I followed iCodez's suggestion, but am not provided with a new error messsage,
return (z[0])*x**6 + (z[1])*x**5 + (z[2])*x**4 + (z[3])*x**3 + (z[4])*x**2 + (z[6])*x + z[7]
IndexError: index 7 is out of bounds for axis 0 with size 7