Beispiel #1
0
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>

# Exercise 6.4 from Strogatz
# Plot phase portraits for a number of ODEs

import sys
sys.path.append('../')

import matplotlib.pyplot as plt, matplotlib.colors as colors, phase, numpy as np, rk4, utilities
for mu in [1, 2, 3]:
    plt.figure()
    X, Y, U, V, fixed = phase.generate(f=lambda x, y: (x * (1 - y), mu * y *
                                                       (x - 1)),
                                       nx=64,
                                       ny=64,
                                       xmin=-0.05,
                                       xmax=3.0,
                                       ymin=-0.05,
                                       ymax=3.0)
    phase.plot_phase_portrait(X,
                              Y,
                              U,
                              V,
                              fixed,
                              title=r'$\dot{x}=x(1-y),\dot{y}=\mu y(y-1)$',
                              suptitle='Example 6.5.19 - Lotka-Volterra')

plt.show()
Beispiel #2
0
# it under the terms of the GNU General Public License as published by
# the Free Software already_foundation, either version 3 of the License, or
# (at your option) any later version.

# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>

# Stability of fixed point

import sys,matplotlib.pyplot as plt
sys.path.append('../')
import  phase

def f(x,y):
    return (x*y,x*x-y)

plt.figure(figsize=(20,20))

X,Y,U,V,fixed_points = phase.generate(f=f,xmin=-10.0,xmax=+10.0,ymin=-10.0,ymax=+10.0,nx=256,ny=256)

phase.plot_phase_portrait(X,Y,U,V,fixed_points,title=r'$\dot{x}=xy,\dot{y}=x^2-y$',suptitle='Example 6.3.10') 

phase.plot_stability(f=f,fixed_points=fixed_points,R=0.05,Limit=10.0,step=0.1,S=50,N=5000,K=100)

plt.savefig('6-3-10')
plt.show()
Beispiel #3
0
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>

# Exercise 6.4.8 from Strogatz
# Plot phase portraits for a number of ODEs

import sys
sys.path.append('../')
import  matplotlib.pyplot as plt,phase

def f(x,y,a,b,c):
    phi = a*x**c + b*y**c
    return (a*x**c-phi*x,b*y**c-phi*y)

a = 2
b = 0.5
c = 3.25

X,Y,U,V,fixed_points=phase.generate(f=lambda x,y:f(x,y,a,b,c),nx=256,ny=256,xmin=0,xmax=3.5,ymin=0,ymax=3.5)
phase.plot_phase_portrait(X,Y,U,V,fixed_points,
                          title=r'$\dot{{x}}=ax^c-\phi x,\dot{{y}}=by^c-\phi y;\phi=ax^c + by^c,a={0},b={1},c={2}$'.format(a,b,c),
                          suptitle='Example 6.4.8')
phase.plot_stability(f=lambda x,y:f(x,y,a,b,c),fixed_points=fixed_points,Limit=5,step=0.1,N=5000,
                     accept=phase.strict_right_upper_quadrant,K=1)

plt.show()
Beispiel #4
0
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>

# Exercise 6.4 from Strogatz
# Plot phase portraits for a number of ODEs

import sys
sys.path.append('../')
import matplotlib.pyplot as plt, matplotlib.colors as colors, phase, numpy as np, rk4, utilities

X, Y, U, V, fixed = phase.generate(f=lambda x, y: (x * (3 - x - y), y *
                                                   (2 - x - y)),
                                   nx=256,
                                   ny=256,
                                   xmin=-0.5,
                                   xmax=3.5,
                                   ymin=-0.5,
                                   ymax=3.5)
phase.plot_phase_portrait(X,
                          Y,
                          U,
                          V,
                          fixed,
                          title=r'$\dot{x}=x(3-x-y),\dot{y}=y(2-x-y)$',
                          suptitle='Example 6.4.1')
plt.figure()

f = lambda x, y: (x * (3 - 2 * x - y), y * (2 - x - y))

X, Y, U, V, fixed = phase.generate(f=f,
Beispiel #5
0
# Exercise 6.2 from Strogatz
# Plot phase portraits for a number of ODEs

import sys
sys.path.append('../')
import matplotlib.pyplot as plt, matplotlib.colors as colors, phase, numpy as np, rk4


def f(x, y):
    return y, -x + (1 - x * x - y * y) * y


X, Y, U, V, fixed = phase.generate(f=f,
                                   nx=256,
                                   ny=256,
                                   xmin=-1,
                                   xmax=1,
                                   ymin=-1,
                                   ymax=1)

phase.plot_phase_portrait(X,
                          Y,
                          U,
                          V,
                          fixed,
                          title='$\dot{x}=y,\dot{y}=x+(1-x^2-y^2)y$',
                          suptitle='Exercise 6.2.1')

cs = ['r', 'b', 'g', 'm', 'c', 'y']
starts = [(0.5, 0), (0.6, 0), (0.4, 0)]
for xy0, i in zip(starts, range(len(starts))):
Beispiel #6
0
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>

# Exercise 6.1 from Strogatz
# Plot phase portraits for a number of ODEs

import sys
sys.path.append('../')
import  matplotlib.pyplot as plt,matplotlib.colors as colors,phase,numpy as np,rk4

X,Y,U,V,fixed=phase.generate(f=lambda x,y:(x-y,1-np.exp(x)))
phase.plot_phase_portrait(X,Y,U,V,fixed,title=r'$\dot{x}=x-y,\dot{y}=1-e^x$',suptitle='Example 6.1.1') 
plt.figure()

X,Y,U,V,fixed=phase.generate(f=lambda x,y:(x-x**3,-y))
phase.plot_phase_portrait(X,Y,U,V,fixed,title=r'$\dot{x}=x-x^3,\dot{y}=-y$',suptitle='Example 6.1.2') 
plt.figure()

X,Y,U,V,_=phase.generate(f=lambda x,y:(x*(x-y),y*(2*x-y)))
phase.plot_phase_portrait(X,Y,U,V,[(0,0)],title=r'$\dot{x}=x(x-y),\dot{y}=y*(2x-y)$',suptitle='Example 6.1.3') 
plt.figure()

X,Y,U,V,fixed=phase.generate(f=lambda x,y:(y,x*(1+y)-1))
phase.plot_phase_portrait(X,Y,U,V,fixed,title=r'$\dot{x}=y,\dot{y}=x(1+y)-1$',suptitle='Example 6.1.4') 
plt.figure()
Beispiel #7
0
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>

# Exercise 6.3 from Strogatz
# Plot phase portraits for a number of ODEs

import sys
sys.path.append('../')
import  matplotlib.pyplot as plt,matplotlib.colors as colors,phase,numpy as np,rk4

X,Y,U,V,fixed=phase.generate(f=lambda x,y:(x-y,x*x-4))
phase.plot_phase_portrait(X,Y,U,V,fixed,title=r'$\dot{x}=x-y,\dot{y}=x^2-4$',suptitle='Example 6.3.1') 
plt.figure()

import utilities,rk4

def f(x,y,direction=1):
    return (direction*(y*y*y-4*x),direction*(y*y*y-y-3*x))

X,Y,U,V,fixed=phase.generate(f=f,nx=256, ny = 256,xmin=-100,xmax=100,ymin=-100,ymax=100)

phase.plot_phase_portrait(X,Y,U,V,fixed,title='$\dot{x}=y^3-4x,\dot{y}=y^3-y-3x$',suptitle='Example 6.3.9')

cs = ['r','b','g','m','c','y']    
starts=[ (0,25*i) for i in range(-5,6)]
for xy0,i in zip(starts,range(len(starts))):
Beispiel #8
0
import sys
sys.path.append('../')
import matplotlib.pyplot as plt, phase


def f(x, y):
    return (x * (1 - y), y * (rho - x))


for rho in [0.1, 0.25, 0.5, 1.0, 2.0]:
    plt.figure(figsize=(20, 20))
    X, Y, U, V, fixed_points = phase.generate(f=f,
                                              nx=256,
                                              ny=256,
                                              xmin=0,
                                              xmax=3.5,
                                              ymin=0,
                                              ymax=3.5)
    phase.plot_phase_portrait(
        X,
        Y,
        U,
        V,
        fixed_points,
        title=r'$\dot{{x}}=x(1-y),\dot{{y}}=y(\rho-x);\rho={0}$'.format(rho),
        suptitle='Example 6.4.4')
    phase.plot_stability(f=f,
                         fixed_points=fixed_points,
                         Limit=5,
                         step=0.1,
Beispiel #9
0
''' Q1.2 A limit cycle with analytic Floquet exponent'''

from sys               import path
from matplotlib.pyplot import figure, savefig,show
from phase             import generate,plot_phase_portrait,plot_stability


def floquet(q,p):
    return (p+q*(1-q*q-p*p),-q+p*(1-q*q-p*p))

figure(figsize=(20,20))
X,Y,U,V,fixed_points = generate(f=floquet,
                                nx   = 256,
                                ny   = 256,
                                xmin = -1.2,
                                xmax = 1.2,
                                ymin = -1.2,
                                ymax = 1.2)

plot_phase_portrait(X,Y,U,V,fixed_points,
                    main_title = r'$\dot{p}=p+q(1-q^2-p^2),\dot{q}=-q+p(1-q^2-p^2)$',
                    supertitle = 'Q1.2 A limit cycle with analytic Floquet exponent.'
                                ' (ChaosBook.org version 14.5.7, exercise 5.1)',
                    xname      = '$p$',
                    yname      = '$q$')

plot_stability(f            = floquet,
               fixed_points = fixed_points,
               Limit        = 0.99,
               step         = 0.1,