# Julia has fantastic language interopability¶

Julia has macros and code generation tools which are utilized by interop packages for seamless integration.

# Julia's Syntax is Familiar¶

Source: Higham: An Algorithmic Introduction to Numerical Simulation of Stochastic Differential Equations

In [ ]:
%BPATH1 Brownian path simulation
function [t,W]=BPATH1(T,N)
randn('state',100)
dt = T/N;
dW = zeros(10,N);
W = zeros(10,N);

dW(:,1) = sqrt(dt)*randn(1,10);
W(:,1) = dW(:,1);

for j = 2:N
dW(:,j) = sqrt(dt)*randn(1,10);
W(:,j) = W(:,j-1) + dW(:,j);
end
t = [0:dt:T-dt];
end

% In Another File...

f = @() BPATH1(1,10000);
timeit(f,2)
[t,W] = BPATH1(1,10000);
plot(t,W,'r-')
xlabel('t','FontSize',16)
ylabel('W(t)','FontSize',16,'Rotation',0)

In [1]:
using Random
function bpath(T,N)
Random.seed!(100)
dt = T/N
dW = zeros(10,N)
W = zeros(10,N)

dW[:,1] = sqrt(dt)*randn(10)
W[:,1] = dW[:,1]

for j = 2:N
dW[:,j] .= sqrt(dt)*randn(10)
W[:,j] .= W[:,j-1] .+ dW[:,j]
end
[0:dt:T-dt],W
end # Translation took < 1 minute
@time t,W = bpath(1,100000)
@time t,W = bpath(1,100000)
# 10x speedup over MATLAB
using Plots; gr(fmt = :png)
plot(t,W',color=:red,xlabel="t",ylabel="W(t)")

  1.530038 seconds (1.99 M allocations: 155.214 MiB, 12.95% gc time)
0.187599 seconds (500.01 k allocations: