Skip to content

Instantly share code, notes, and snippets.

@7shi
Created February 13, 2018 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7shi/12aa5a30264911a52b38bf497350ea90 to your computer and use it in GitHub Desktop.
Save 7shi/12aa5a30264911a52b38bf497350ea90 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1×128 Array{Float64,2}:\n",
" 6.92448e-310 6.92444e-310 0.0 0.0 … 0.0 6.92448e-310 6.92444e-310"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"N_grid,dx,dy = 128,0,0\n",
"x_cen = N_grid/2 + 1 + dx\n",
"y_cen = N_grid/2 + 1 + dy\n",
"XX = Array{Float64}(1,N_grid)\n",
"YY = Array{Float64}(1,N_grid)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"for i in 1 : N_grid\n",
" XX[i] = ( i - x_cen ) / N_grid *2\n",
" YY[i] = ( i - y_cen ) / N_grid *2\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"ename": "LoadError",
"evalue": "\u001b[91mTypeError: Type{...} expression: expected UnionAll, got Base.#zeros\u001b[39m",
"output_type": "error",
"traceback": [
"\u001b[91mTypeError: Type{...} expression: expected UnionAll, got Base.#zeros\u001b[39m",
"",
"Stacktrace:",
" [1] \u001b[1minclude_string\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::String, ::String\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./loading.jl:522\u001b[22m\u001b[22m"
]
}
],
"source": [
"z = zeros{Float64}(N_grid,N_grid)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"128×128 Array{Float64,2}:\n",
" 0.0 0.0 0.0 0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 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z = zeros(Float64,N_grid,N_grid)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"bessel_map (generic function with 1 method)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function bessel_map(N_grid, nu, k, th0, dx, dy)\n",
" x_cen = N_grid/2 + 1 + dx\n",
" y_cen = N_grid/2 + 1 + dy\n",
" \n",
" XX = Array{Float64}(1,N_grid)\n",
" YY = Array{Float64}(1,N_grid)\n",
" \n",
" for i in 1 : N_grid\n",
" XX[i] = ( i - x_cen ) / N_grid *2\n",
" YY[i] = ( i - y_cen ) / N_grid *2\n",
" end\n",
" \n",
" z = zeros(Float64,N_grid,N_grid)\n",
" \n",
" for ix in 1:N_grid\n",
" for iy in 1:N_grid\n",
" xx = (1.0 * ix - x_cen)/N_grid *2\n",
" yy = (1.0 * iy - y_cen)/N_grid *2\n",
" theta = atan2(yy, xx)\n",
" rr = sqrt(xx^2.0 + yy^2.0)\n",
" \n",
" if rr <= 1.0\n",
" \n",
" z[ix,iy] = besselj(nu, rr*j0[k,nu+1]) * cos(nu*theta - th0)\n",
" end\n",
" end\n",
" end\n",
" \n",
" return z\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"ename": "LoadError",
"evalue": "\u001b[91mUndefVarError: j0 not defined\u001b[39m",
"output_type": "error",
"traceback": [
"\u001b[91mUndefVarError: j0 not defined\u001b[39m",
"",
"Stacktrace:",
" [1] \u001b[1mbessel_map\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Int64, ::Int64, ::Int64, ::Float64, ::Float64, ::Float64\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./In[13]:24\u001b[22m\u001b[22m",
" [2] \u001b[1minclude_string\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::String, ::String\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./loading.jl:522\u001b[22m\u001b[22m"
]
}
],
"source": [
"bessel_map(128,0,1,0.0,0.0,0.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.6.2",
"language": "julia",
"name": "julia-0.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment