What I want to share today is how you can use Julia's type system to hide performance gains in your code. What I mean is this: in many cases you may find out that the optimal way to do some calculation is not a "clean" solution. What do you do? What I want to do is show how you can define special arrays which are wrappers such that these special "speedups" are performed in the background, while having not having to keep all of that muck in your main algorithms. This is easiest to show by example.
The examples I will be building towards are useful for solving ODEs and SDEs. Indeed, these tricks have all been implemented as part of DifferentialEquations.jl and so these examples come from a real use case! They really highlight a main feature of Julia: ... READ MORE
Let's take a program which plots the standard logistic map:
r = 2.9:.00005:4; numAttract = 100; steady = ones(length(r),1)*.25; for i=1:300 ## Get to steady state steady = r.*steady.*(1-steady); end x = zeros(length(steady),numAttract); x[:,1] = steady; for i=2:numAttract ## Now grab some values at the attractor x[:,i] = r.*x[:,i-1].*(1-x[:,i-1]); end using PyPlot; fig = figure(figsize=(20,10)); plot(collect(r),x,"b.",markersize=.06) savefig("plot.png",dpi=300);
This plots the logistic map. If you take the same code and change the array ... READ MORE