Skip to content

Instantly share code, notes, and snippets.

@xiangze
Last active January 13, 2018 04:34
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 xiangze/b0603f3ad3b6d67e1fe780ea9e9c2c0f to your computer and use it in GitHub Desktop.
Save xiangze/b0603f3ad3b6d67e1fe780ea9e9c2c0f to your computer and use it in GitHub Desktop.
Juliaで複素積分
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Juliaで複素積分"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 複素積分∮の定義"
]
},
{
"cell_type": "code",
"execution_count": 228,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"∮ (generic function with 1 method)"
]
},
"execution_count": 228,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function ∮(f,path)\n",
" s=0\n",
" for i in 2:length(path)\n",
" s=s+f((path[i]+path[i-1])/2)*(path[i]-path[i-1])\n",
" end\n",
" return s\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 複素平面上での四角い積分経路"
]
},
{
"cell_type": "code",
"execution_count": 236,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"□ (generic function with 4 methods)"
]
},
"execution_count": 236,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function □(leftdown,rightup,num)\n",
" r1=real(leftdown)\n",
" r2=real(rightup)\n",
" i1=imag(leftdown)\n",
" i2=imag(rightup)\n",
" a=linspace(r1,r2,num)+i1*im\n",
" b=linspace(i1,i2,num)*im+r2\n",
" c=linspace(r2,r1,num)+i2*im\n",
" d=linspace(i2,i1,num)*im+r1\n",
" return vcat(vcat(a,b),vcat(c,d))\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 複素関数"
]
},
{
"cell_type": "code",
"execution_count": 245,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"f (generic function with 1 method)"
]
},
"execution_count": 245,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g(z)=z*3\n",
"f(z)=1/z"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"gは極を持たない複素平面全域で正則な関数\n",
"\n",
"fは原点に極を持つ"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 積分の実行"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 極を囲わない積分路"
]
},
{
"cell_type": "code",
"execution_count": 237,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8.881784197001252e-16 + 3.552713678800501e-15im"
]
},
"execution_count": 237,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cc=□(3+im,4+3*im,4)\n",
"∮(g,cc)"
]
},
{
"cell_type": "code",
"execution_count": 238,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.0 + 0.0im"
]
},
"execution_count": 238,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"∮(g,□(3+im,0+im,4))"
]
},
{
"cell_type": "code",
"execution_count": 239,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"1.5543122344752192e-15 - 4.440892098500626e-16im"
]
},
"execution_count": 239,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cr=□(1+im,3+im)\n",
"∮(g,cr)"
]
},
{
"cell_type": "code",
"execution_count": 242,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.0547118733938987e-15 - 3.552713678800501e-15im\n",
"-0.00018306775067675196 + 0.0009021823204503621im\n"
]
}
],
"source": [
"c=□(1+im,3+2*im)\n",
"println(∮(g,c))\n",
"println(∮(f,c))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### fの極を囲う積分路"
]
},
{
"cell_type": "code",
"execution_count": 243,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.0 + 0.0im\n",
"9.71445146547012e-17 + 6.291421562431563im\n"
]
}
],
"source": [
"c=□(-5+-5im,4+4*im)\n",
"println(∮(g,c))\n",
"println(∮(f,c))"
]
},
{
"cell_type": "code",
"execution_count": 251,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6.283185307179586"
]
},
"execution_count": 251,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2*π"
]
},
{
"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