Source code for numerical.ode_model

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Mathmatical models governed by ordinary differential equations.

Describes initial value problems as systems of first order ordinary differential
equations.

:Date: 2019-05-25

.. module:: ode_model
  :platform: *nix, Windows
  :synopsis: Models of ordinary differential equations.

.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
"""
from __future__ import division, print_function
from numpy import array, cos, sin, dot, square
from numpy.linalg import inv

[docs]def disk(x, t, *p): """Rotation of an eccentric disk. :param x: values of the function :type x: list :param t: time :type t: list :param `*p`: parameters of the function * diameter * eccentricity * torque """ qp1 = x[3] qp2 = x[4] qp3 = x[5] M = array([[1, 0, cos(x[2])], [0, 1, -sin(x[2])], [0, 0, 1]]) y = array([[-2*p[0]*x[3]+sin(x[2])*x[5]**2-2*p[0]*cos(x[2])*x[5]-x[0]], \ [-2*p[0]*x[4]+cos(x[2])*x[5]**2-2*p[0]*sin(x[2])*x[5]-x[1]], \ [p[2]-p[1]*x[1]*sin(x[2])+p[1]*x[0]*cos(x[2])]]) qp46 = dot(inv(M), y) qp4, qp5, qp6 = qp46.reshape(-1,).tolist() # 2d array to 1d array to list return qp1, qp2, qp3, qp4, qp5, qp6
[docs]def disk_nm(xn, xpn, xppn, t, *p): """Rotation of an eccentric disk. :param xn: values of the function :type xn: list :param xpn: first derivative values of the function :type xpn: list :param xppn: second derivative values of the function :type xppn: list :param t: time :type t: list :param `*p`: parameters of the function * diameter * eccentricity * torque """ N = array([[xppn[0]+cos(xn[2])*xppn[2]+2*p[0]*xpn[0]+2*p[0]*cos(xn[2])*xpn[2]-sin(xn[2])*square(xpn[2])+xn[0]], [xppn[1]-sin(xn[2])*xppn[2]+2*p[0]*xpn[1]-2*p[0]*sin(xn[2])*xpn[2]-cos(xn[2])*square(xpn[2])+xn[1]], [xppn[2]+p[1]*(-cos(xn[2])*xn[0]+sin(xn[2])*xn[1])-p[2]]]) dN = array([[1, 0, -sin(xn[2]*xppn[2])-2*p[0]*sin(xn[2])*xpn[2]-cos(xn[2])*square(xpn[2])], [0, 1, -cos(xn[2]*xppn[2])-2*p[0]*cos(xn[2])*xpn[2]+sin(xn[2])*square(xpn[2])], [-p[1]*cos(xn[2]), p[1]*cos(xn[2]), p[1]*(sin(xn[2])*xn[0]+cos(xn[2])*xn[1])]]) dNp = array([[2*p[0], 0, 2*p[0]*cos(xn[2])-2*sin(xn[2])*xpn[2]], [0, 2*p[0], -2*p[0]*sin(xn[2])-2*cos(xn[2])*xpn[2]], [0, 0, 0]]) dNpp = array([[1, 0, cos(xn[2])], [0, 1, -sin(xn[2])], [0, 0, 1]]) return N, dN, dNp, dNpp
[docs]def disk_nmmdk(xn, xpn, xppn, t, *p): """Rotation of an eccentric disk. :param xn: values of the function :type xn: list :param xpn: derivative values of the function :type xpn: list :param xppn: second derivative values of the function :type xppn: list :param t: time :type t: list :param `*p`: parameters of the function * diameter * eccentricity * torque """ rm = array([[xppn[0]+cos(xn[2])*xppn[2]], [xppn[1]-sin(xn[2])*xppn[2]], [xppn[2]]]) rmx = array([[0, 0, -sin(xn[2]*xppn[2])], [0, 0, -cos(xn[2]*xppn[2])], [0, 0, 0]]) rmxpp = array([[1, 0, cos(xn[2])], [0, 1, -sin(xn[2])], [0, 0, 1]]) rd = array([[2*p[0]*xpn[0]+2*p[0]*cos(xn[2])*xpn[2]-sin(xn[2])*square(xpn[2])], [2*p[0]*xpn[1]-2*p[0]*sin(xn[2])*xpn[2]-cos(xn[2])*square(xpn[2])], [0]]) rdx = array([[0, 0, -2*p[0]*sin(xn[2])*xpn[2]-cos(xn[2])*square(xpn[2])], [0, 0, -2*p[0]*cos(xn[2])*xpn[2]+sin(xn[2])*square(xpn[2])], [0, 0, 0]]) rdxp = array([[2*p[0], 0, 2*p[0]*cos(xn[2])-2*sin(xn[2])*xpn[2]], [0, 2*p[0], -2*p[0]*sin(xn[2])-2*cos(xn[2])*xpn[2]], [0, 0, 0]]) rk = array([[xn[0]], [xn[1]], [p[1]*(-cos(xn[2])*xn[0]+sin(xn[2])*xn[1])]]) rkx = array([[ 1, 0, 0], [ 0, 1, 0], [-p[1]*cos(xn[2]), p[1]*cos(xn[2]), p[1]*(sin(xn[2])*xn[0]+cos(xn[2])*xn[1])]]) f = array([[0], [0], [p[2]]]) return rm, rmx, rmxpp, rd, rdx, rdxp, rk, rkx, f
if __name__ == '__main__': True