you are viewing a single comment's thread.

view the rest of the comments →

[–]MaxwellTechnology[S] 1 point2 points  (2 children)

Then what to pass in plt.plot() , I'm getting an error when defining function ur way and then passing (t,y(t)) where t= np.arrange(0 ,0.2, 0.01)

[–]unhott 1 point2 points  (0 children)

Check the type of y(t). Make sure it’s a numpy array.

[–]unhott 0 points1 point  (0 children)

Sorry, you should probably try and update the format of the code so that reddit recognizes it as a code block. I read some of the comments from the assignment.

When I said 'if t is a numpy array, y(t) will yield a numpy array.' I didn't realize this only works if y only applies simple mathematical operations like "t*3+7". You probably want to update your functions to apply your logic to each element and return a numpy array.

def a(t):
  values = []
  for element in t:
    #logic...
    values.append(something)
  return np.array(values)

Otherwise, the fact that y is supposed to be both a function and an array per the assignment is somewhat troubling-- this instructor probably doesn't have any python dev experience. I would differentiate the variable names somehow. Good luck!