Tommy Ofinger
Tommy Ofinger

Reputation: 11

Python Equivalent of MATLAB's deval

As the title suggests, I am looking for an equivalent function or a suggestion on how to achieve the same thing deval does in MATLAB but in Python.

Code:

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

#define model function that returns ds/dt, di/dt/ and dr/dt

def epidemic_model(state, t):
     s, i, r = state
     d_s = -0.06 * s * i
     d_i = 0.06 *s * i - 7*i
     d_r = 7 * i
     return [d_s, d_i, d_r]


t = np.arange(0, 1, 0.01)
init_state = [990, 10, 0]

state = odeint(epidemic_model, init_state, t)
plt.xlabel('time')
plt.ylabel('population') 
plt.plot(t, state)

Now my task is to find at which time the number of the infected population and recovered population is the same.

I would do this in MATLAB using deval, I am looking for a Python version of this.

Upvotes: 1

Views: 718

Answers (1)

kaxil
kaxil

Reputation: 18844

Check dsolve function in the sympy package below:

http://docs.sympy.org/latest/modules/solvers/ode.html#dsolve

Solves any (supported) kind of ordinary differential equation and system of ordinary differential equations.

Also, solve a system of ordinary differential equations using integrate.solve_ivp from scipy package:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html#scipy-integrate-solve-ivp

This function numerically integrates a system of ordinary differential equations given an initial value

Upvotes: 1

Related Questions