Matlab solve system of differential equations numerically

Systems of ODEs solving by MATLAB

Photo by Jonathan Kemper on Unsplash

Ordinary differential equations, or ODEs, play a significant role in different applications. And often, the numerical techniques are best to approach to solve them. Let’s see how we do this in MATLAB by solving first-order systems of ordinary differential equations. Here we concerned about the application of the spread of HIV infection.

Equations

The equations are momentary balances based on the amount of healthy cells (H), infected cells (I), and viral count (V). In this equation system, Terms with a positive sign increase the equivalent quantity of cells or virus. Similarly, phrases with a minus sign reduce the number of cells or viruses.

Matlab solve system of differential equations numerically

Three differential equations about the spread of HIV

The model contains six parameters kr1,kr2,kr3,kr4,kr5 and kr6, that provide cell death rates, infection dissemination, virus replication, and other processes that influence HIV spread in the body.

Parameters Values

As above mentioned, there are six parameters with their correspondings values.

Parameters values

Simulation by MATLAB

I hope you all know that we can obtain a solution to a single differential equation by using MATLAB. Then let’s see how we do this with the ode45 function in MATLAB solving a system of ODEs. As previously stated, the ode45 function is the most often used ODE solver in MATLAB.

To do this, first, we have to convert the system of ODEs into a new format. Therefore, the first step is to combine all of these ODEs into a single equation for a single variable that we will call X.

Matlab solve system of differential equations numerically

Values in terms of the vector components of ‘X’

The strategy is to create X, a column vector with three components, each corresponding to one of the variables H, I, and V. Then, we take the derivative of each element of X. The corresponding equation determines each value from the original system.

Now that we have a vectorized system of ODEs, the next step is to construct a MATLAB function. This function computes the derivative vector value for use with the ode45 function. Our ‘model’ function will generate a single output dXdt for given input values t and X.

Function constructed with respective parameter values

The final step is to invoke the ode45 function by passing a handle to our derivative function, a vector containing the initial and final time values. In here initial conditions are H_0 = 1000000, I_0 = 0 and V_0 = 100.

Defined initial conditions

Conclusion

The solution to our differential equation is recorded in the output variables ‘Xsol’ and ‘tsol’ when we run this script. The first output is a vector containing the time values used to compute the numerical solution. The second output is a matrix containing the calculated value of variable X for each time in ‘tsol’. Individual columns can then be extracted for additional analysis or visualisation.

References

Nowak, M. and May, R. M. Virus dynamics: mathematical principles of immunology and virology: mathematical principles of immunology and virology. Oxford university press, 2000.

How do you solve differential equations using numerical methods?

Contents.
2.1 Euler method..
2.2 Backward Euler method..
2.3 First-order exponential integrator method..
2.4 Generalizations..
2.5 Advanced features..
2.6 Alternative methods..
2.7 Parallel-in-time methods..

Can you use MATLAB to solve differential equations?

You can solve the differential equation by using MATLAB® numerical solver, such as ode45 . For more information, see Solve a Second-Order Differential Equation Numerically.

What does Dsolve do in MATLAB?

The MATLAB command dsolve computes symbolic solutions to ordinary differential equations. dsolve('eq1','eq2',...,'cond1','cond2',...,'v') symbolically solves the ordinary differential equations eq1, eq2,... using v as the independent variable.

Does MATLAB have a PDE solver?

What Types of PDEs Can You Solve with MATLAB? The MATLAB® PDE solver pdepe solves initial-boundary value problems for systems of PDEs in one spatial variable x and time t. You can think of these as ODEs of one variable that also change with respect to time.