How to numerically solve this system of arbitrary number of differential equations? - python

How can I solve a system of k differential equations with derivatives appearing in every equation? I am trying to use Scipy's solve_ivp.
All the equations are of the following form:
equations
How can this system of equations be numerically solved using any solver? using solve_ivp, it seems you should be able to write every equation independent of the other ones, which seems not possible in this case when we have more than 2 equations.

If you set C[i]=B[i,i] then you can transform the equations to the linear system B*z'=A. This can be solved as
zdot = numpy.linalg.solve(B,A)
so that the derivative is this constant solution of a constant linear system, and the resulting solution for z is linear, z(t)=z(0)+zdot*t.

Related

Python modeling language for ordinary differential equations?

I am working on ordinary differential equations that I want to solve using numerical methods in Python. Some of these ODEs are chemical equations, e.g. A + B > C with stoichiometry coefficient sigma. This leads to the differential equation du/dt = sigma * a * b.
To do this, the classical method is to use e.g. a Runge-Kutta solver, such as the one in Scipy's integrate.ode.
Instead, I would like to use a modeling language similar to cvxpy is for convex optimization. This method would allow to formally define the ODE and automatically solve the equation. It would be similar, in Python, to what is done in OpenModelica.
Is there such a tool?

Matlab or Python tool for solving continuous replicator equation

I am trying to numerically solve a continuous replicator partial differential equation in order to model evolution in a competitive system. The equation takes the form of a second-order nonlinear integral PDE, with the specific PDE in the attached image.
Do you know of any tools in MATLAB or Python that can help in solving these forms of equations? I've looked at MATLAB's built-in solver and PDE toolbox, but neither can do second-order integral PDEs.

Solution to nonlinear differential equation with non-constant mass matrix

If I have a system of nonlinear ordinary differential equations, M(t,y) y' = F(t,y), what is the best method of solution when my mass matrix M is sometimes singular?
I'm working with the following system of equations:
If t=0, this reduces to a differential algebraic equation. However, even if we restrict t>0, this becomes a differential algebraic equation whenever y4=0, which I cannot set a domain restriction to avoid (and is an integral part of the system I am trying to model). My only previous exposure to DAEs is when an entire row is 0 -- but in this case my mass matrix is not always singular.
What is the best way to implement this numerically?
So far, I've tried using Python where I add a small number (0.0001) to the main diagonals of M and invert it, solving the equations y' = M^{-1}(t,y) F(t,y). However, this seems prone to instabilities, and I'm unsure if this is a universally appropriate means of regularization.
Python doesn't have any built-in functions to deal with mass matrices, so I've also tried coding this in Julia. However, DifferentialEquations.jl states explicitly that "Non-constant mass matrices are not directly supported: users are advised to transform their problem through substitution to a DAE with constant mass matrices."
I'm at a loss on how to accomplish this. Any insights on how to do this substitution or a better way to solve this type of problem would be greatly appreciated.
The following transformation leads to a constant mass matrix:
.
You need to handle the case of y_4 = 0 separately.

Solving Numerical four coupled differential equations using Runge-Kutta

How can I solve the following four coupled equations numerically in Python?
I need a source code !!!!!
y'(1) = (-wa+wp)*y(2)+g*y(4)
y'(2) = (-wa+2wp)*y(1)-g*y(3)
y'(3) = (wa-wp)*y(4)+g*y(2)
y'(4) =-(wa+wp)*y(3)-g*y(1)
Check out Integration and ODEs (scipy.integrate). Exactly which solver you use will depend upon the boundary conditions you have: particularly solve_ivp for initial value problems and solve_bvp for boundary value problems.

Solve N^2 nonlinear equations system

I am trying to solve a system of N*N nonlinear equations, but I get stuck and do not understand what is the problem.
My equations are :
h_{j,i} = (T/2) \sum_{k=1..N}{f(h_{k,j})} - (T/2) f(h_{i,j})
for i and j in [1..N]^2, and where the h are the unknowns, f is a known function and T is a parameter.
In all the examples I have found, there are maybe two or three equations/unknowns, so one can implement the equations directly. Nevertheless, I have too many equations here, and I do not understand how to implement a code without explicitly writing all the equations, and using fsolve (on python).
Thanks for your help

Categories

Resources