I have performed a convolution using the $\texttt{fft}$ function in MatLab. However the result I get does not match the same convolution if I perform it using the Fourier transform in WolframAlpha. The functions $f_1$ and $f_2$ that I am convolving are (for simplicity) given by $$ f_1 = f_2 = e^{-\pi x^2}. $$
With WolframAlpha I use the convolution theorem so I have
$$
F[f_1\ast f_2] = F[f_1]\cdot F[f_2] = (F[f_1]^2),
$$
and therefore
$$
f_1\ast f_2 = F^{-1}(F[f_1]^2).
$$
WolframAlpha gives an explicit answer of
$$
f_1\ast f_2 =
\frac{e^{-\pi t^2/2}}{2 \sqrt{\pi}},
$$
and the plot looks like

However this does not match the image I get from my MatLab code (which can be found below).
Here is my MatLab code
L = 2; % length
M = 200; % number of samples
dx = L/M; % sample interval
x = -L/2:dx:L/2-dx; % x coordinates
f_1 = exp(-pi*(x.^2)); % Gaussian 1
f_2 = exp(-pi*(x.^2)); % Gaussian 2 (same as 1)
figure(1)
plot(x,f_1,x,f_2,'--'); title('functions');
xlabel('x (m)');
%% Step 2. Perform convolution
F_1 = fft(f_1); % transform f_1
F_2 = fft(f_2); % transform f_2
F_0 = F_1.*F_2; % multiply pointwise
f_0 = ifft(F_0)*dx; % inverse transform and scale
f = fftshift(f_0); % center result
figure(1)
hold on
plot(x,f); title('Convolution');
xlabel('x')
So why do the images not match? The formulas and code seem very straightforward, and I've rechecked them several times, so I can't see why the images are inconsistent. Can anyone see what's going wrong?
Short answer. Both computations are correct, and they differ simply because the result from WolframAlpha is not the convolution of your functions.
Longer answer. Fourier transform is not a single transform. It is actually a family of transforms involving some parameters. For instance, Mathematica implements the following formulation
\begin{align*} \mathcal{F}[f](\omega) &= \sqrt{\frac{|b|}{(2\pi)^{1-a}}} \int_{-\infty}^{\infty} f(t) e^{ib\omega t} \, \mathrm{d}t, \\ \mathcal{F}^{-1}[F](t) &= \sqrt{\frac{|b|}{(2\pi)^{1+a}}} \int_{-\infty}^{\infty} F(\omega) e^{-ib\omega t} \, \mathrm{d}\omega \end{align*}
with the default parameter $(a, b) = (0, 1)$. Under this formulation, the convolution is Fourier-transformed to
$$ \mathcal{F}[f * g] = \sqrt{\frac{(2\pi)^{1-a}}{|b|}} \mathcal{F}[f] \mathcal{F}[g]. $$
Notice that we have extra constant factor. That said, in order for your formulation to give a correct answer, you should choose a correct parameter so that the above constant factor reduces to $1$. (And unfortunately, the default choice does not work for you.)
One convenient choice is $(a, b) = (0, -2\pi)$, which corresponds to the following unitary Fourier transform
$$ \mathcal{F}[f](\omega) = \int_{-\infty}^{\infty} f(t) e^{-2\pi i \omega t} \, \mathrm{d}t, \qquad \mathcal{F}^{-1}[F](t) = \int_{-\infty}^{\infty} F(\omega) e^{2\pi i \omega t} \, \mathrm{d}\omega. $$
Under this choice, you should get the correct answer as follows: