0

I have a discontinuous function I_v(P) in which the equation changes when P => 1. How do I successfully generate I_v values so I can make a plot?

P = np.linspace(1e-3,1e+1,1000)
if P < 1:
    I_v = P*math.e**(P)*(a_0 + a_1*P + a_2*P**2 + a_3*P**3 + a_4*P**4 + a_5*P**5 - math.log(P))
else:
    I_v = (P**4 + e_1*P**3 + e_2*P**2 + e_3*P + e_4)/(P**4 + f_1*P**3 + f_2*P**2 + f_3*P + f_4)
Error: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I want the P values to evaluated one at a time, not as an array.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 1
    I think you could use a generator: https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do – Pete Jan 09 '23 at 21:03

0 Answers0