f= input('ingrese la funcion, usando: @(t)LA_FUNCION: '); %ingresa la funcion como parametro T= input('ingrese el periodo T: '); %ingresa el periodo como parametro N= input('ingrese el numero de iteraciones N: '); %ingresa N como parametro w0 = 2*pi/T; suma=@(t) integral(f,-T/2,T/2)/2; for k=1:N fun_a=@(t) f(t).*cos(k*w0*t); fun_b=@(t) f(t).*sin(k*w0*t); a_k=2/T*integral(fun_a,-T/2,T/2); % calculo del coeficiente a b_k=2/T*integral(fun_b,-T/2,T/2); %calculo del coeficiente b suma= @(t) suma(t) +a_k*fun_a(t) + b_k*fun_b(t); %sumatoria de la serie de Fourier end t= -T/2:0.01:T/2; x_t=f(t); x_Nt=suma(t); plot(t,x_t,t,x_Nt)
the problem is that you are supposed to approximate the function with a sum of sines and cosines with certain amplitudes. Your summation is not of sines and cosines, but rather in the case of cos,
b_k* f(t)*cos(k*w0*t)
T = 10; f = @(t) 6*(heaviside(t)-1/2); % for example w0 = 2*pi/T; N = 10; suma=@(t) integral(f,-T/2,T/2)/2 for k=1:N fun_a=@(t) f(t).*cos(k*w0*t); fun_b=@(t) f(t).*sin(k*w0*t); a_k=2/T*integral(fun_a,-T/2,T/2); % calculo del coeficiente a b_k=2/T*integral(fun_b,-T/2,T/2); %calculo del coeficiente b % suma= @(t) suma(t) +a_k*fun_a(t) + b_k*fun_b(t); %sumatoria de la serie de Fourier suma= @(t) suma(t) +a_k*cos(k*w0*t) + b_k*sin(k*w0*t); %sumatoria de la serie de Fourier end t= -T/2:0.01:T/2; x_t=f(t); x_Nt=suma(t); figure(1) plot(t,x_t,t,x_Nt)
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.