Piko
Piko

Reputation: 23

Matlab plotting graph

I am trying to draw Fourier series of a square wave that is shifted as phi, but I am getting this error:

parse error near line 9 of file /home/cihad/Masaüstü/grafik.m syntax error

But there is nothing to may be a problem at the line 9

t = 0:0.001:2*pi;
A = 12;
n = 3;
p =pi/6;
fourier = 0
for n=1:2:100
    
    fourier_an = A*(2*sin(n*p)*cos(n*pi)-2*sin(n*p)))*cos(n*t)/(n*pi); ---> line 9
    fourier_bn = A*(2*cos(n*p)-2*cos(n*pi)*cos(n*p)+cos(n*p))*sin(n*t)/(n*pi);
    fourier = fourier_an + fourier_bn + fourier;
  
end

plot(t,fourier); 

Upvotes: 1

Views: 29

Answers (1)

lolloz98
lolloz98

Reputation: 109

There is a parenthesis which should not be there. Try:

t = 0:0.001:2*pi;
A = 12;
n = 3;
p =pi/6;
fourier = 0;
for n=1:2:100
    
    fourier_an = A*(2*sin(n*p)*cos(n*pi)-2*sin(n*p))*cos(n*t)/(n*pi);
    fourier_bn = A*(2*cos(n*p)-2*cos(n*pi)*cos(n*p)+cos(n*p))*sin(n*t)/(n*pi);
    fourier = fourier_an + fourier_bn + fourier;
  
end

plot(t,fourier); 

Upvotes: 1

Related Questions