# MATLAB MATLAB plotting error?

Hello,

I've written a piece of code in MATLAB, to depict the function x(t)

I have the Fourier coefficients of this function as following:

a(k) = 1/(k.*pi)^2

where k is even and otherwise a(k) = 0.

also we know that x(t+5) = x(t)

my code is :
Code:
function [zaribX] = Ak(k)

if ~((mod(k,2) == 1) || k==0)
zaribX=1./(k.*pi).^2;
else zaribX=0;
end
return;
end

function [x] = FunctionX(Kmax,t)
x = 0;
for m = 0:Kmax
f = 2 .* abs(Ak(m)) .* cos( m .* ((2.*pi)./5) .* t + angle(Ak(m)));
x = x+f;
end
return;
end
problem is, when MATLAB plots the function, it appears to have a period of 2.5 , and not 5. Could anyone help me see what's going wrong? Thanks a lot.

Related Math Software Workshop News on Phys.org

### Want to reply to this thread?

"MATLAB plotting error?"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving