# Trying to plot an imaginary signal in python

I am trying to plot cos(x) + isin(x)

this is a 2 part question

part 1

I am tryin to plot a signal cos(x) + i*sin(x)

In python when i am trying to calculate np.sqrt(-1) for i,It is giving NaN Thats why i am not getting any plot of the data

Sample_rate = 1000
Duration = 5
i = np.sqrt(-1)
print(i)
def generate_sine_and_cosine_wave(freq, sample_rate, duration):
sines = np.linspace(0, duration, sample_rate*duration, endpoint=False)
frequencies_sines = sines * freq
cosines = np.linspace(1, duration, sample_rate*duration, endpoint=False)
frequencies_cosines = cosines * freq
x = i*sines+cosines
y = np.cos((2 * np.pi) * frequencies_cosines +frequencies_sines)
return x, y

x, y = generate_sine_and_cosine_wave(2, Sample_rate, Duration)
plt.plot(x, y)
plt.show()


part 2

And if i try to code to get cos(x) + sin(x)? My actual intention was to produce the signal with 2 HZ frequency but when I am trying to produce datapoints for the signal(for cos(x) + i sin(x)), then i am unable to produce the frequency as 2 HZ

Help me to correct the code

• Hi John! You actually forgot to ask a question! Jul 13 '21 at 10:41
• but: you really need to read the python documentation: 1j is the imaginary unit in python. sqrt, on the other hand, or negative real numbers is undefined. Jul 13 '21 at 10:42
• yeah that is why can you suggest any other way to implement a code to plot that complex signal>> Jul 13 '21 at 10:46
• I just did exactly that! 1j is valid python for "imaginary unit". And I can't read the python docs for you! Jul 13 '21 at 10:47
• ohh okay thanks.... Jul 13 '21 at 11:39