MATLAB: Strange problem with sin.

sin problem

So i´m doing the following:
t = [0:0.5:5];
f = 2;
pha = pi/3;
x=sin(2 * pi * f * t + pha);
plot(t,x)
and the result on x will be
I´m pretty sure it´s my fault because i´m quite new, but i have already finished harder exercises and i just can´t find my mistake in this one. Any thoughts?

Best Answer

"Strange problem with sin."
So what is the problem? You did not tell us what you expect to get for the output values, or describe what the supposed "problem" is. We cannot guess what you imagine the output should be.
However what is clear is that sin has correctly calculated the sine values of the input values that you have given it, which have a step of 2*pi:
>> 2 * pi * f * t + pha
ans =
1.0472 7.3304 13.6136 19.8968 26.1799 32.4631 38.7463 45.0295 51.3127 57.5959 63.8791
>> diff(2 * pi * f * t + pha)
ans =
6.2832 6.2832 6.2832 6.2832 6.2832 6.2832 6.2832 6.2832 6.2832 6.2832
>> diff(2 * pi * f * t + pha)/2/pi
ans =
1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
All you have shown is that every 2*pi of its input sine's output repeats, which is exactly what we would expect (and is by definition of a circle).