Suppose x runs from (0 to 10); now for x<=5, I need to plot 8*x
and else I need to plot 50*x
.
My attempt:
import matplotlib.pyplot as plt
import numpy as np
def f(x):
if x<=3:
return (8*x)
else:
return (50*x)
t=np.linspace(0,10,100)
plt.plot(t,f(t))
plt.ylabel('s')
plt.xlabel('t')
plt.show()
But it is showing error:
The truth value of an array with more than one element is ambiguous.