I have written code in mathematica which can successfully generate a figure for me, and I'm trying to do the same thing in matlab but I've been stuck on it for a while now. I'm pretty sure it is my understanding of how matlab operates that is the problem, (as opposed to matlab's inability to do what mathematica can do) but I haven't been able to make it work.
Could someone take a look at my code and determine what I'm doing wrong with the code, it is actually pretty simple. Look at the matematica code first to see what it should be doing.
I've attached 4 pictures (mathematica 1 & 2 ....also Matlab 1 & 2): Two are of the mathematica code/plot. The first mathematica pic being the first function plotted and then the second mathematica pic is the end result. And there are two pics of my matlab code/plot - the first is of the first function (which is identical to the mathematica one according to the graph), and then the second pic is the end result (which is wrong when plotting EOM2 according to the graph).
----------------------------------------------------------------------------------------------
My mathematica code looks like this:
f[x_] := PDF[NormalDistribution[], x]
v1 := 1.1
v2 := .9
f1 := 13.3
f2 := 20
EOM1[x_] := Sum[BesselJ[Abs[i], v1]*f[x + f1*i], {i, -2, 2}]
EOM2[x_] := Sum[BesselJ[Abs[i], v2]*EOM1[x + f2*i], {i, -2, 2}]
Overlay[{
Plot[EOM1[x], {x, -100, 100}, PlotRange -> {0, .5},
PlotStyle -> Red],
Plot[12*PDF[NormalDistribution[0, 20], x], {x, -100, 100},
PlotRange -> {0, .5}]
}]
-----------------------------------------------------------------------------------------------
My MATLAB code looks like this:
clear all; clc;
xStep = 1;
x = (-50:xStep:50);
V1 = 1.1;
V2 = .9;
F1 = 13.3;
F2 = 20;
k = (-2:1:2);
s = 1;
u = 0;
for x1 = min(x):max(x)
for k1 = min(k):max(k)
BSL2a(k1+max(k)+1,x1+max(x)+1) = besselj(abs(k1),V1).*(1/(s*sqrt(2*pi))).*exp((-1./2*s.^2).*(x1+F1.*k1-u).^2);
end
end
BSL2aSum = sum(BSL2a);
plot(x,BSL2aSum,'b'); hold off;
for x1 = min(x):max(x)
for k1 = min(k):max(k)
EOM2(k1+max(k)+1,x1+max(x)+1) = normpdf((x1+(F1.*k1)+(F2.*k1)),0,1).*besselj(abs(k1),V1).*besselj(abs(k1),V2);
end
end
plot(x,sum(EOM2))