数値計算
- 非線形連立方程式
- 解の数値計算の方法
- こちら のpdf
- より
- となるように を選ぶとすると、2次より高次の項を無視すると
- を得る
- を繰り返し計算する
- 以前の rootSolve の記事
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
- Solving Equation on the Computer と こちら のコメントで教えていただいた数値計算について
- 数値計算
- Euler's method
- Improved Euler method
- Runge-Kutta method
- その他(Wiki)
- について
- Euler's method
- Improved Euler method
- 2点の傾きの平均をとる
- Runge-Kutta method
- ソースで用いた条件は以下
- 初期条件:
- の範囲の計算
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))
場の成分の計算
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
- の一次元(one-dimentional, first-order system)の挙動を扱う
- ここで関数 は の関数としておく
- ではsecond-order になるのでここでは扱わない
- 2.1 A Geometric Way of Thinking
- のグラフを 平面に書くことでベクトル場を描き、安定解、不安定解などを判定する
- 2.2 Fixed Points and Stability
- グラフを描いて、平衡解とその安定性を判定する
- 2.3 Population Growth
- が与えられ、そのグラフから解だけでなく時間発展の様子を判断する
- 2.4 Linear Stability Analysis
- 平衡解 の近くでの挙動を線型の方程式で近似する
- 小さい揺らぎ を与える
- により
- で与えられる
- で揺らぎが増加、 で揺らぎが減衰する
- 時定数も計算できる
- の時は、Tayler展開の高次の項が関わる
- 2.5 Existence and Uniqueness
- 2.6 Impossibility of Oscillations
- これまでの の例では振動がみられない
- 非常に粘性の高い溶液中のバネによる運動のモデルもこれに相当する
- 2.7 Potentials
- ポテンシャルの導入による安定性の判定
- によりポテンシャルを導入する
- ここで なのでポテンシャルは時間とともに減少する
- ポテンシャルの極値をあたえる が平衡解で、それが下に凸(極小)ならば安定である
- 平衡解について と が同値
- 安定性について と が同値なので
- 2.8 Solving Equation on the Computer
力学の教科書
- 作者: Steven H. Strogatz
- 出版社/メーカー: CRC Press
- 発売日: 2001/01/15
- メディア: ペーパーバック
- 購入: 2人 クリック: 46回
- この商品を含むブログ (5件) を見る
-
- 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
- 2. Flows on the Line
- 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