Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#Source-Sink model
#参考:三浦岳、発生の数理、京都大学学術出版会、2015、4.3
#julia v0.6
using Plots
gr()
dx=0.05 #
dt=0.1 #単位時間
u0=zeros(1/dx) #初期濃度
Du=0.01
function fixConc(arr)
v=arr
v[1]=1.0
v[end]=0.0
return v
end
function left(arr)
prepend!(collect(Iterators.take(arr,length(arr)-1)),arr[1])
end
function right(arr)
append!(collect(Iterators.drop(arr,1)),arr[end])
end
function diffusion(arr)
Du*(left(arr)-arr+right(arr)-arr)/dx/dx
end
function dudt(arr)
fixConc(arr+dt*diffusion(arr))
end
u=u0
anim = @animate for g=0:250
plot(u,
xticks=0:1:20,
ylim=(0.0,1.5),
yticks=0.0:0.1:1.5,
seriestype=:bar,
title="gen = $g")
u=dudt(u)
end
@time gif(anim, "tmp/diff02.gif", fps = 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment