{"id":14989269,"url":"https://github.com/warrenweckesser/odeintw","last_synced_at":"2025-04-09T07:09:50.470Z","repository":{"id":16567820,"uuid":"19321715","full_name":"WarrenWeckesser/odeintw","owner":"WarrenWeckesser","description":"odeintw provides a wrapper of scipy.integrate.odeint that allows it to handle complex and matrix differential equations.","archived":false,"fork":false,"pushed_at":"2025-01-09T05:34:40.000Z","size":357,"stargazers_count":40,"open_issues_count":1,"forks_count":12,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-09T07:09:45.830Z","etag":null,"topics":["differential-equations","ode","python","scipy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WarrenWeckesser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-04-30T17:31:40.000Z","updated_at":"2025-01-09T05:34:42.000Z","dependencies_parsed_at":"2023-09-23T09:54:00.176Z","dependency_job_id":"fab6fffa-902d-42f2-86c1-bd244e3ca39c","html_url":"https://github.com/WarrenWeckesser/odeintw","commit_stats":{"total_commits":73,"total_committers":1,"mean_commits":73.0,"dds":0.0,"last_synced_commit":"5d2cbbeb66113edcb6faf9c4268a3506991c5b22"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarrenWeckesser%2Fodeintw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarrenWeckesser%2Fodeintw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarrenWeckesser%2Fodeintw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarrenWeckesser%2Fodeintw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WarrenWeckesser","download_url":"https://codeload.github.com/WarrenWeckesser/odeintw/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994122,"owners_count":21030050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["differential-equations","ode","python","scipy"],"created_at":"2024-09-24T14:17:58.142Z","updated_at":"2025-04-09T07:09:50.455Z","avatar_url":"https://github.com/WarrenWeckesser.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"odeintw\n=======\n\n`odeintw` provides a wrapper of `scipy.integrate.odeint` that allows it to\nhandle complex and matrix differential equations.  That is, it can solve\nequations of the form\n\n    dZ/dt = F(Z, t, param1, param2, ...)\n\nwhere `t` is real and `Z` is a real or complex array.\n\nSince `odeintw` is just a wrapper of `scipy.integrate.odeint`, it requires\n`scipy` to be installed.\n\n`odeintw` is available on PyPI: https://pypi.org/project/odeintw/\n\n\nExample 1\n---------\n\nTo solve the equations\n\n    dz1/dt = -z1 * (K - z2)\n    dz2/dt = L - M*z2\n\nwhere `K`, `L` and `M` are (possibly complex) constants, we first define the\nright-hand-side of the differential equations::\n\n    def zfunc(z, t, K, L, M):\n        z1, z2 = z\n        return [-z1 * (K - z2), L - M*z2]\n\nThe Jacobian is\n\n    def zjac(z, t, K, L, M):\n        z1, z2 = z\n        jac = np.array([[z2 - K, z1], [0, -M]])\n        return jac\n\nThe following calls `odeintw` with appropriate arguments\n\n    # Initial conditions.\n    z0 = np.array([1+2j, 3+4j])\n\n    # Desired time samples for the solution.\n    t = np.linspace(0, 5, 101)\n\n    # Parameters.\n    K = 2\n    L = 4 - 2j\n    M = 2.5\n\n    # Call odeintw\n    z, infodict = odeintw(zfunc, z0, t, args=(K, L, M), Dfun=zjac,\n                          full_output=True)\n\nThe components of the solution can be plotted with `matplotlib` as follows\n\n    import matplotlib.pyplot as plt\n\n    color1 = (0.5, 0.4, 0.3)\n    color2 = (0.2, 0.2, 1.0)\n    plt.plot(t, z[:, 0].real, color=color1, label='z1.real', linewidth=1.5)\n    plt.plot(t, z[:, 0].imag, '--', color=color1, label='z1.imag', linewidth=2)\n    plt.plot(t, z[:, 1].real, color=color2, label='z2.real', linewidth=1.5)\n    plt.plot(t, z[:, 1].imag, '--', color=color2, label='z2.imag', linewidth=2)\n    plt.xlabel('t')\n    plt.grid(True)\n    plt.legend(loc='best')\n    plt.show()\n\nPlot:\n\n![](https://github.com/WarrenWeckesser/odeintw/blob/main/examples/odeintw_example1.png)\n\n\nExample 2\n---------\n\nWe'll solve the matrix differential equation\n\n    dA/dt = C * A\n\nwhere `A` and `C` are real 2x2 matrices.\n\nThe differential equation is defined with the function\n\n    def asys(a, t, c):\n        return c.dot(a)\n\nBoth `a` and `c` are assumed to be `n x n` matrices.  The function\n`asys` will work for any `n`, but we'll specialize to `2 x 2` in our\nimplementation of the Jacobian:\n\n    def ajac(a, t, c):\n        # asys returns [[F[0,0](a,t), F[0,1](a,t),\n        #                F[1,0](a,t), F[1,1](a,t)]]\n        # This function computes jac[m, n, i, j]\n        # jac[m, n, i, j] holds dF[m,n]/da[i,j]\n        jac = np.zeros((2,2,2,2))\n        jac[0, 0, 0, 0] = c[0, 0]\n        jac[0, 0, 1, 0] = c[0, 1]\n        jac[0, 1, 0, 1] = c[0, 0]\n        jac[0, 1, 1, 1] = c[0, 1]\n        jac[1, 0, 0, 0] = c[1, 0]\n        jac[1, 0, 1, 0] = c[1, 1]\n        jac[1, 1, 0, 1] = c[1, 0]\n        jac[1, 1, 1, 1] = c[1, 1]\n\n(As with `odeint`, giving an explicit Jacobian is optional.)\n\nNow create the arguments and call `odeintw`:\n\n    # The matrix of coefficients `c`.  This is passed as an\n    # extra argument to `asys` and `ajac`.\n    c = np.array([[-0.5, -1.25],\n                  [ 0.5, -0.25]])\n\n    # Desired time samples for the solution.\n    t = np.linspace(0, 10, 201)\n\n    # a0 is the initial condition.\n    a0 = np.array([[0.0, 1.0],\n                   [2.0, 3.0]])\n\n    # Call `odeintw`.\n    sol = odeintw(asys, a0, t, Dfun=ajac, args=(c,))\n\n\nThe solution can be plotted with `matplotlib`:\n\n    import matplotlib.pyplot as plt\n\n    plt.figure(1)\n    plt.clf()\n    color1 = (0.5, 0.4, 0.3)\n    color2 = (0.2, 0.2, 1.0)\n    plt.plot(t, sol[:, 0, 0], color=color1, label='a[0,0]')\n    plt.plot(t, sol[:, 0, 1], color=color2, label='a[0,1]')\n    plt.plot(t, sol[:, 1, 0], '--', color=color1, linewidth=1.5, label='a[1,0]')\n    plt.plot(t, sol[:, 1, 1], '--', color=color2, linewidth=1.5, label='a[1,1]')\n    plt.legend(loc='best')\n    plt.grid(True)\n    plt.show()\n\nPlot:\n\n![](https://github.com/WarrenWeckesser/odeintw/blob/main/examples/odeintw_example2.png)\n\n\n*Copyright (c) 2015, Warren Weckesser*\n\nAll rights reserved.\nSee the LICENSE file for license information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarrenweckesser%2Fodeintw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwarrenweckesser%2Fodeintw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarrenweckesser%2Fodeintw/lists"}