lundi 7 septembre 2015

Create a function with an if statement inside

I want to write a function such as f(x) with an if statement and make this function accessible from another file, more or less as if it were a sin(x) function. Moreover, I'd like to plot this function for a range of x values, but I keep getting an error. Here's my code:

import numpy as np
import matplotlib.pyplot as plt

fyd=450/1.15

def f(es):
    if es < 0.002:
        return fyd*es/0.002
    else:
        return fyd;


x=np.arange(0.0000,0.01,0.0001)

plt.plot(x,f(x))
plt.show()

And this is the error message I get:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Aucun commentaire:

Enregistrer un commentaire