From 10cdca6bd220aa8cf4ae4ff131f809eb9b439285 Mon Sep 17 00:00:00 2001 From: Gerardo Marx Date: Tue, 9 Jun 2020 23:26:34 -0500 Subject: [PATCH] symbolic ODE and series --- readme.md | 2 ++ scripts/program-02a.py | 10 ++++++++++ scripts/program-02b.py | 10 ++++++++++ scripts/program-02c.py | 9 +++++++++ 4 files changed, 31 insertions(+) create mode 100644 readme.md create mode 100644 scripts/program-02a.py create mode 100644 scripts/program-02b.py create mode 100644 scripts/program-02c.py diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..5e19599 --- /dev/null +++ b/readme.md @@ -0,0 +1,2 @@ +# Dynamical systems examples Lynch +Repository for examples related with book Dynamical system with applications using Python by Stephen Lynch. diff --git a/scripts/program-02a.py b/scripts/program-02a.py new file mode 100644 index 0000000..1f15c01 --- /dev/null +++ b/scripts/program-02a.py @@ -0,0 +1,10 @@ +# Program 02a: A simple separable ODE. See Example 1. +from sympy import dsolve, Eq, Function, symbols, pprint +t = symbols('t') +x = symbols('x', cls=Function) +dxdt = x(t).diff(t) +de = Eq(dxdt, -t/x(t)) +print('Program 02a:\n') +pprint(de) +sol = dsolve(de, x(t)) +pprint(sol) diff --git a/scripts/program-02b.py b/scripts/program-02b.py new file mode 100644 index 0000000..43c753e --- /dev/null +++ b/scripts/program-02b.py @@ -0,0 +1,10 @@ +# Program 02b: The logistic equation; example 4-ch2. +from sympy import dsolve, Eq, Function, symbols, pprint +t, b, d = symbols('t beta sigma') +P = symbols('P', cls=Function) +dPdt = P(t).diff(t) +de = Eq(dPdt, P(t)*(b-d*P(t))) +print('program 02b:\n') +pprint(de) +sol = dsolve(de, P(t)) +pprint(sol) diff --git a/scripts/program-02c.py b/scripts/program-02c.py new file mode 100644 index 0000000..31dff3b --- /dev/null +++ b/scripts/program-02c.py @@ -0,0 +1,9 @@ +# Program 02c: Power series solution first order ODE; exa 7 chp 2 +from sympy import dsolve, Function, pprint +from sympy.abc import t +x = Function('x') +dxdt = x(t).diff(t) +ode = dxdt+t*x(t)-t**3 +sol = dsolve(ode, hint='1st_power_series', n=8, ics={x(0): 1}) +print('Solution:\n') +pprint(sol)