数値計算

f<-function(x,y){(x-3)^2+y^2-3}
g<-function(x,y){sin(x)+exp(y-1)-1}

# fx<-function(x){2*(x-3)}
# fy<-function(y){2*y}
# gx<-function(x){cos(x)}
# gy<-function(y){exp(y-1)}

x<-0
y<-0
T<-100
d<-0.01

for(t in 1:T){

A<-matrix(c(
(f(x+d,y)-f(x-d,y))/(2*d),(f(x,y+d)-f(x,y-d))/(2*d),
(g(x+d,y)-g(x-d,y))/(2*d),(g(x,y+d)-g(x,y-d))/(2*d)
),byrow=T,2,2)


dX<- -solve(A)%*%c(f(x,y),g(x,y))
x<-x+dX[1]
y<-y+dX[2]
}
print(x);print(y)
  • 実行
# 実行
> print(x);print(y)
[1] 1.997356
[1] -1.41234

Solving Equation on the Computer

  • ソースで用いた条件は以下
    • \dot{x}=e^{-x}
    • 初期条件:x(0)=0
    • 0 \leq t \leq T の範囲の計算
f<-function(x){exp(-x)}
T0<-0
T<-10
x0<-0

# 解析解
F<-function(t){log(t+1)}
t<-seq(from=T0,to=T,by=0.01)
plot(t,F(t),type="l",col=1,ylim=c(0,F(T)))

# オイラー法
dt<-0.5
Nt<-T/dt
xold<-x0
xn<-c(x0)
for(nt in 1:Nt){
	xnew<-xold+f(xold)*dt
	xn<-c(xn,xnew)
	xold<-xnew
	}

t<-seq(from=T0,to=T,by=dt)
par(new=T)
plot(t,xn,col=2,ylim=c(0,F(T)))

# improved-オイラー法
dt<-0.5
Nt<-T/dt
xold<-x0
xn<-c(x0)
for(nt in 1:Nt){
	x1<-xold+f(xold)*dt
	xnew<-xold+(f(xold)+f(x1))/2*dt
	xn<-c(xn,xnew)
	xold<-xnew
	}

t<-seq(from=T0,to=T,by=dt)
par(new=T)
plot(t,xn,col=3,ylim=c(0,F(T)))

# ルンゲ-クッタ法:fourth-order Runge-Kutta
dt<-1
Nt<-T/dt
xold<-x0
xn<-c(x0)
for(nt in 1:Nt){
	k1<-f(xold)*dt
	k2<-f(xold+k1/2)*dt
	k3<-f(xold+k2/2)*dt
	k4<-f(xold+k3)*dt
	xnew<-xold+(k1+k2*2+k3*2+k4)/6
	xn<-c(xn,xnew)
	xold<-xnew
	}

t<-seq(from=T0,to=T,by=dt)
par(new=T)
plot(t,xn,col=4,ylim=c(0,F(T)))

legend(x=c(4,10),y=c(0.5,1),c("Analytical solution","Euler's method","improved Euler method","fourth-order Runge-Kutta method"),col=c(1,2,3,4),lty=c(1,0,0,0),pch=c(-1,1,1,1))

場の成分の計算

  • ポテンシャルから場を計算する
    • こちら の2.7 にもポテンシャルがでてくる
  • つまりは一階偏微分係数を求める
Nx<-10
Ny<-10

V<-matrix((1:(Nx*Ny))^2,Nx,Ny,byrow=T)
V_x<-matrix(0,Nx,Ny)

V_x[c(-1,-Nx),]<-(V[c(-1,-2),]-V[c(-(Nx-1),-Nx),])/2
V_x[1,]<-V[2,]-V[1,]
V_x[Nx,]<-V[Nx,]-V[Nx-1,]

persp(V,col=4)
persp(V_x,col=4)

# gx<-gxy<-1
# Ix<-matrix(0,Nx-1,Ny)
# Ix<-(-1)*gx*(V[-1,]-V[-Nx,])+(-1)*gxy*(V_x[-1,]+V[-Nx,])/2

Flows on the Line

  • 2. Flows on the Line
    • 2.0 Introduction
    • 2.1 A Geometric Way of Thinking
    • 2.2 Fixed Points and Stability
    • 2.3 Population Grouth
    • 2.4 Linear Stability Analysis
    • 2.5 Existence and Uniqueness
    • 2.6 Impossibility of Oscillations
    • 2.7 Potentials
    • 2.8 Solving Equation on the Computer
  • 2.0 Introduction
    • \dot{x} = f(x) の一次元(one-dimentional, first-order system)の挙動を扱う
    • ここで関数 f(x)x(t) の関数としておく
    • f(x,t) ではsecond-order になるのでここでは扱わない
  • 2.1 A Geometric Way of Thinking
    • f(x) のグラフを  x-\dot{x} 平面に書くことでベクトル場を描き、安定解、不安定解などを判定する
  • 2.2 Fixed Points and Stability
    • グラフを描いて、平衡解とその安定性を判定する
  • 2.3 Population Growth
    • f(x) が与えられ、そのグラフから解だけでなく時間発展の様子を判断する
  • 2.4 Linear Stability Analysis
    • 平衡解 x^* の近くでの挙動を線型の方程式で近似する
    • 小さい揺らぎ\eta(t) = x(t) - x^* を与える
    • \dot{\eta} = \dot{x} = f(x) = f(\eta + x^*) = \sum_{n=0}^\infty \frac{f(x^*)}{n!} \eta^n = f(x^*) +f^{(1)}(x^*) \eta + O(\eta^2) により
    • \dot{\eta} = f'(x*)\eta で与えられる
      • f'(x*) > 0 で揺らぎが増加、f'(x*) < 0 で揺らぎが減衰する
      • 時定数も計算できる
      •  f'(x^*) =0 の時は、Tayler展開の高次の項が関わる
  • 2.5 Existence and Uniqueness
    • 初期値が不安定解の場合、解が一意でないことがある
    • Existens and Uniquness Theorem
      • 初期値問題  \dot{x} = f(x), \, x(0) = x_0 について 実数軸の開区間上でf(x), \, f'(x) が連続でx_0 が実軸上の点ならば、初期値問題はある区間(-\tau,\tau) に 解x(t) が存在し、一意である。
        • つまり、f(x) が十分滑らかならば解が存在して一意になるが、任意の時間で解が存在するという訳ではない
  • 2.6 Impossibility of Oscillations
    • これまでの \dot{x} = f(x) の例では振動がみられない
    • 非常に粘性の高い溶液中のバネによる運動のモデルもこれに相当する  m\ddot{x} \ll b\dot{x}
  • 2.7 Potentials
    • ポテンシャルの導入による安定性の判定
    • f(x) = - \frac{dV}{dx} によりポテンシャルを導入する
    • ここで \frac{dV}{dt} = \frac{dV}{dx}\frac{dx}{dt} =-  \{ \frac{dx}{dt} \} ^2 \leq 0 なのでポテンシャルは時間とともに減少する
    • ポテンシャルの極値をあたえる x が平衡解で、それが下に凸(極小)ならば安定である
      • 平衡解について  \frac{dV}{dx} = 0f(x) = 0 が同値
      • 安定性について \frac{d^2V}{dx^2} > 0f' (x) <0 が同値なので
  • 2.8 Solving Equation on the Computer

力学の教科書

Nonlinear Dynamics And Chaos: With Applications To Physics, Biology, Chemistry, And Engineering (Studies in Nonlinearity)

Nonlinear Dynamics And Chaos: With Applications To Physics, Biology, Chemistry, And Engineering (Studies in Nonlinearity)

    • 1. Overview
  • Part 1. One-Dimensional Flows
    • 2. Flows on the Line
      • 2.0 Introduction
      • 2.1 A Geometric Way of Thinking
      • 2.2 Fixed Points and Stability
      • 2.3 Population Grouth
      • 2.4 Linear Stability Analysis
      • 2.5 Existence and Uniqueness
      • 2.6 Impossibility of Oscillations
      • 2.7 Potentials
      • 2.8 Solving Equation on the Computer
    • 3. Bifurcations
    • 4. Flows on the Circle
  • Part 2. Two-Dimensional Flows
    • 5. Linear Systems
    • 6. Phase Plane
    • 7. Limit Cycles
    • 8. Bifurcations Revisited
  • Part 3. CHAOS
    • 9. Lorenz Equations
    • 10. One-Dimensional Maps
    • 11. Fractals
    • 12. Strange Attractors

拡散

  • メモ
  • 3次元はこちら
  •  \begin{matrix}\frac{\par^2}{\par r^2}  & = &  \frac{\par^2}{\par x^2} \cos^2\theta + \frac{\par^2}{\par y \par x}\sin \theta \cos \theta +\frac{\par^2}{\par x \par y} \sin \theta \cos \theta + \frac{\par^2}{\par y^2} \sin^2 \theta \\ & = & ( \frac{\par}{\par x} \cos\theta +\frac{\par}{\par y} \sin\theta)^2 \end{matrix}
  • \sin \theta \cos \theta について
    • \theta = \frac{\pi}{4} のとき \frac{1}{2}
    • \theta = \frac{3\pi}{4} のとき -\frac{1}{2}
      • ここで \frac{1}{2} がでてくるわけでキョリは関係ない?
      • 偏微分係数の計算にナナメのマスを使っているだけ
  • さらに \theta については  \frac{\pi}{4} に限らず以下のように与える
    •  \tan\theta = \frac{\Delta y}{\Delta x}
  • その上で
    •  \phi = \frac{\pi}{2} - \theta として
    • \sin \phi \cos \phi をもう片方の係数とするべきだろう
  • ここで
    • \frac{\par^2}{\par y \par x}\frac{\par^2}{\par x \par y} が(ななめの)どちらの方向を表すのか分かっていないので、シミュレーションでたしかめられるかどうか
    •  \tan\theta = t が与えられれば \sin \theta \cos \theta =\frac{t}{1+t^2}\sin \phi \cos \phi =\frac{-t}{1+t^2} で計算できる