MATLAB Plot of a periodic function

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 9K views
ColdStart
Messages
18
Reaction score
0
letsa say my function is:
x(n) = 1 + sin((2*pi)/N)*n + 3*cos((2*pi)/N)*n + cos( ((4*pi)/N)*n + pi/2);

when i plot it inside a loop, with a loop variable being n, i have something llike increasing slope... even when i set a period N to be 8,4 or whateva..

on the other side... when i plot the same function expanded using euler's expansion:
x(n) = 1 + (1/(2*1i))*(exp(1i*2*pi*n/N) - exp(-1i*2*pi*n/N)) + 1.5*(exp(1i*2*pi*n/N) + exp(-1i*2*pi*n/N)) + 0.5*(exp(1i*(4*pi*n/N + pi/2)) + exp(-1i*(4*pi*n/N + pi/2)));

i do get a function which looks periodic.. that is a little bit weird, or am i missing something?

p.s. and the second function is obtained from the Fourier ak Coofficients..
 
Physics news on Phys.org
Why use a loop. Make an array of all n-variables and then a array of all x(n) solutions for then to plot.

ie. n=0:0.01:2*pi;
x=...;
plot(n,x)

Also you might want to put a .(period) in front of all mutiplication signs, or else it does a matrix multiplication.
ie. >> x=1+sin(2.*pi*n)+3.*cos(2.*pi.*n)+cos((4.*pi.*n)+ pi/2);
 
thank you! yeah! i have no idea sometimes its confusing when in the books they put period outside of parenthesis!.. that make sense now!