The intention is to plot the following equation: P*sin(x)/x + cos(x), for P = 1.6 and x in [0, 5], which, ignoring the green-filled areas, should look someting like:
However, from the following code:
x = 0 : 0.01 : 5; % ka/pi, where k-wavevector, a-lattice spacing.
P = 1.6; % 2*m*U_0 / hbar^2.
rhs = P * sinc(x*pi) + cos(x*pi);
rhs2 = P * ( sin(x*pi) / x*pi) + cos(x*pi);
plot(x, rhs, '--b', x, rhs2, 'b', x, -1*ones(size(x)), 'r', x, 1*ones(size(x)), 'r')
axis([0 5 -3 3])
xlabel('ka/pi')
legend('P*sinc(x) + cos(x)', '(2mU_0b)/(hbar^2) * sin(ka)/ka + cos(ka)', 'y = -1', 'y = 1')
what I currently get is:
What am I doing wrong here?
I am on Windows 10, Octave-4.2.1
The MATLAB definition of the sinc
is sinc(t) = sin(pi t)/(pi t)
, i.e. you must not multiply by pi
in the rhs definition:
x = 0 : 0.01 : 5; % ka/pi, where k-wavevector, a-lattice spacing.
P = 1.6; % 2*m*U_0 / hbar^2.
rhs = P * sinc(x)+ cos(x*pi);
rhs2 = P * (sin(x*pi) / x*pi) + cos(x*pi);
plot(x, rhs, 'b', x, rhs2, '--b', x, -1*ones(size(x)), 'r', x, 1*ones(size(x)), 'r')
axis([0 5 -3 3])
xlabel('ka/\pi')
legend('P*sinc(x) + cos(x)', '(2mU_0b)/(hbar^2) * sin(ka)/ka + cos(ka)', 'y = -1', 'y = 1')
Also note that for t=0
sinc(t)=1
, whereas your rhs2
has sin(x pi)/(x pi)
, which for x=0
returns NaN
, hence the difference in the two signals, as the second is a pure cosine.
I missed the element wise division and lack of brackets in the OP's sinc
implementation, see am304's answer for that. Note that even when using element wise division and brackets you'll still miss the point at x=0
, since that'll result to NaN
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With