Hi I have this piecewise function and its graph :cosine and right graph
I supposed to implement that piecewise in python and get the same graph at the next. My code is this :
import numpy as np
import matplotlib.pyplot as plt
def f(time):
T = time
Ts1 = 0.3
Ts2 = 0.4
ind = 0
t_axis = np.linspace(0,T,100)
ft=np.arange(100.0)
for t in t_axis:
if t<Ts1:
ft[ind] = (np.cos(np.pi*t/Ts1))
ind += 1
elif Ts1<=t<Ts2:
ft[ind] = (np.cos(np.pi*(t+Ts2-Ts1)/(Ts1)))
ind += 1
else:
ft[ind] = (0)
ind +=1
return ft,t_axis
a,b = f(1)
plt.plot(b,a)
plt.show()
And unfotunately i get this weird graph :
{{{ I didn't made the multiplication of e(t) and the constants. Because in the end this can not change the graph (just brings some amplification or level shifting i figure out.) }}}
And here are my questions:
1- Is my code OK for that function ?
2- Could it be something related with the values of Ts1 and Ts2. Because i chosed them randomly.
3-If i achieve to get the right graph, how should i change the cosine argument in order to visualise graph over a couple periods ?