So I've been banging my head against a little MATLAB problem for the past four hours or so.
I'm trying to compute the Fourier series of a triangle wave (for the purpose of none other then my own enjoyment). For some reason I can't seem to get the code right:
Code:
clear;
clc;
format long;
itteration_count = 50;
sum_count = 50;
peroid = 2*pi;
origin = 0;
t = origin:peroid/itteration_count:peroid;
f = 1:itteration_count+1;
for k = 0:itteration_count
sum = 0;
for n = 1:2:sum_count
sum = sum + (((((-1)^((n-1)/2))/n^2)*sin((n*pi*t(k+1)))/peroid));
end
f(k+1) = sum*(8/(pi^2));
end
plot(t,f)
EDIT:
Never mind, I just set the iteration count higher and it works.