Skip to main content

ode integration rk4 rk runge kutta

Project description

Header pic

Runge-Kutta 4

Actions Status PyPI - License PyPI - Python Version PyPI - Format PyPI

A simple implementation of Runge-Kutta for python. This supports both python 2 and python 3.

Setup

Install

The preferred method of installation is: pip install pyrk

Develop

git clone https://github.com/walchko/pyrk
cd pyrk
poetry build
poetry install

Usage

See the examples in the docs folder or a simple one:

from __future__ import division, print_function
from pyrk import RK4
import numpy as np
import matplotlib.pyplot as plt

def vanderpol(t, xi, u):
    dx, x = xi
    mu = 4.0 # damping

    ddx = mu*(1-x**2)*dx-x
    dx = dx

    return np.array([ddx, dx])

rk = RK4(vanderpol)
t, y = rk.solve(np.array([0, 1]), .01, 200)

y1 = []
y2 = []
for v in y:
    y1.append(v[0])
    y2.append(v[1])

plt.plot(y1, y2)
plt.ylabel('velocity')
plt.xlabel('position')
plt.grid(True)
plt.show()

MIT License

Copyright (c) 2015 Kevin J. Walchko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrk-0.8.1.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

pyrk-0.8.1-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page