Last active
August 29, 2015 14:02
-
-
Save ViralBShah/c6aee8a845080b3efb33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*(r1::RemoteRef,r2::RemoteRef)=@spawnat r2.where fetch(r1)*fetch(r2) | |
function prefix8(y,*) | |
if length(y)!=8; error("length 8 only"); end | |
for i in [2,4,6,8]; y[i]=y[i-1]*y[i]; end | |
for i in [ 4, 8]; y[i]=y[i-2]*y[i]; end | |
for i in [ 8]; y[i]=y[i-4]*y[i]; end | |
for i in [ 6 ]; y[i]=y[i-2]*y[i]; end | |
for i in [ 3,5,7 ]; y[i]=y[i-1]*y[i]; end | |
y | |
end | |
function laplace_iter_vec(u, dx2, dy2, Niter, N) | |
for i = 1:Niter | |
u[2:N-1, 2:N-1] = ((u[1:N-2, 2:N-1] + u[3:N, 2:N-1])*dy2 + (u[2:N-1,1:N-2] + u[2:N-1, 3:N])*dx2) * (1./ (2*(dx2+dy2))) | |
end | |
return u | |
end | |
function laplace_iter_devec(u, dx2, dy2, Niter, N) | |
uout = copy(u) | |
for iter = 1:Niter | |
for i = 2:N-1 | |
for j = 2:N-1 | |
uout[i,j] = ((u[i-1,j]+u[i+1,j])*dy2 + (u[i,j-1]+u[i,j+1])*dx2 ) * (1./(2*(dx2+dy2))) | |
end | |
end | |
u, uout = uout, u | |
end | |
return u | |
end | |
*(α::Number, g::Function)= x->α*g(x) # Scalar times function | |
*(f::Function,λ::Number) = x->f(λ*x) # Scale the argument | |
*(f::Function,g::Function)= x->f(g(x)) # Function Composition |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment