Matlab Code for Solving Differential Equations in Chemical Engineering

Matlab programming for chemical engineering is important in designing equipment in process engineering. In chemical engineering, we have to solve differential equations to find relationships between different parameters.


Matlab coding for differential equation for reaction engineering

Here we see matlab codes for first order and second order differential equations. Knowing basics for solving differential equation is a must for any chemical engineer.

These differential equations are used to solve problems of batch reactors, plug flow rectors (PFR) and continuous stirred reactors (CSTR).



In this tutorial, we will look how to code a matlab program properly to represent a behavior of a reactor. First, several basic codes are given to understand how to solve differential equations by matlab program.



First order differential equation matlab code with initial conditions

Here, we are going to solve first order differential equation, dy/dt = t. Initial conditions are given as when t = 0, y = 10. Finally, y values against t values are graphed.


Solve dy/dt = t differential equation using matlab


  1. syms y(t)
  2. ode = diff(y,t) == t;
  3. ini_con = y(0)==10;
  4. ysol(t)= dsolve(ode,ini_con);
  5. ezplot(ysol,[0,10]);



First order differential equation matlab code.jpg

ode = diff(y,t) == t;

Here we define the differential equation.



Nonlinear differential equation with initial condition

Here, we are going to solve second order differential equation, [ dy/dt + y ]2 = 1

  1. syms y(t)
  2. ode = (diff(y,t)+y)^2 == 1;
  3. cond = y(0) == 0;
  4. ySol(t) = dsolve(ode,cond);


Questions asked by students. Ask your question and find the answer free.




Related Tutorials