You are on page 1of 13

Reactor Design I

Chemical Engineering Department (3rd course in Chemical Engineering)


Engineering)

2021-22

Using MATLAB for some practical


calculations encountered in Reactor
Design I

Ignacio Aracil Sáez


Mª José Fernández Torres
Rubén Ruiz Femenia
As engineers we use tools for complex
mathematical calculations
 Mathematics should not be the challenge
 Engineering is the challenge
 Know that you have many tools at your
disposal to help you out with mathematics

2
But before all that: how to define functions in
MATLAB
If you want to write a function, for example: f(x)= x2
equivalent to

the function
the independent
variable

Now we can pass arguments


to this function, e.g., x = 3

3
How to define functions with more than one
variable in MATLAB
Area of a rectangle = length × width (apply to l=2 and w=5)

the function

two independent variables

4
Common challenge for engineers: how to solve
differential eqs. or integrals
a) Use your already acquired maths skills
b) Get help from symbolic calculation in Matlab
Analytically
b1) syms x; int(
int( x^2, 1, 2)
Single
b2) syms y(x); dsolve(
dsolve( diff(y) == x^2, y(1)== 0)
ODE

dy/dx = f(x) c) integral( @(x) x.^2, 1, 2)


is given d) [x,y]
x,y] = ode45( @(x,y
@(x,y)
x,y) x^2, [1, 2], 0)
Solve

Numerically
a table (xi,yi) is given
e) trapz(
trapz( xi, yi)
yi)
(or a table (xi) and a function y=f(x))

System of several ODEs


f) [x,Y]
x,Y] = ode45(@system_diff_eqs
ode45(@system_diff_eqs,
system_diff_eqs, [1, 2], y0)
(numerically)

Partial differential equations system g) PDEtool Matlab


(numerically) h) COMSOL 5
a) Use your already acquired maths skills

dP
Solve the ODE: = x2 + 2
dx

We separate variables and integrate:

( )
dP = x 2 + 2 dx

  + 2 dx
( )
2
dP = x
x3
P = + 2 x + constant
 y ( x ) dx
3

6
b1) Get help from symbolic calculation in Matlab
(command “int
int”)
int

 dP =  ( x ) same example
 y ( x ) dx
2
+ 2 dx

• In order to do the integration we also need to


specify that “x” is a symbolic variable

7
b1) Get help from symbolic calculation in Matlab
(command “int
int”)
int

Let’s ask MATLAB


to do the symbolic
integration for us

equivalent to  y ( x ) dx
using >> int(
int(y,x)
y,x) is also valid

expand the previous answer

To add the
integration
constant
Easy peasy!!
peasy!! 8
b1) Get help from symbolic calculation in Matlab
(command “int
int”)
int

You can also solve


a definite integral

Easy peasy!!
peasy!! 9
b2) Get help from symbolic calculation in Matlab
(command “dsolve
dsolve”)
dsolve

If choose to do
it analytically
Practise on your own time the command “dsolve
dsolve”
dsolve

dy
= ty
dt

dy
= ty , y(0) = 2
dt
with initial conditions 10
b2) Get help from symbolic calculation in Matlab
(command “dsolve
dsolve”)
dsolve

Enjoy
while
practising!

11
c) Command “integral
integral”
integral (numerical integration)

For example:

12
How to solve systems of nonlinear equations in
Matlab (“fsolve
fsolve”
fsolve command)

• https://www.youtube.com/watch?v=iEoSvPkJ2
g8

• https://www.youtube.com/watch?v=al-
4ZBLbV_A
13

You might also like