This example is not really testing Fortran vs. Julia, but rather testing the speed of the math library you linked to.

The most expensive part of the fortran code is evaluating sqrt and exp.

For example on a 5600X the current Fortran code (with n=10 000) takes about 2.7 seconds. If I change the definition of M to remove the special functions (M(i,j) = a(i)+ a(j) then it takes .3 seconds. (Using gfortran with -Ofast)

When the special functions are the issue, using the Intel Fortran compiler and Intel MKL will make the code about 2x faster (this is what Matlab or Julia is probably using)

Julia ships with OpenBLAS, in some cases there are pure-Julia "blas-like" routine that can be as fast:

https://github.com/mcabbott/Tullio.jl