You are on page 1of 4

Matilda Ikomi b9064131

Computing and Numerical methods


Matlab assignment 2020

1. Flow chart of MATLAB code

Define Set time span


START constants (time from 0-
k1, k2, k3 100)

Solve ode using Set initial


ODE-45 function conditions/concentratio
ns ([MeOH]= 3 [TG]=1
and the rest is 0)

Assign positions in Define rate Define ODEs


conc matrix with equations r1, r2, for each
species name r3 species using ^

Solve ODEs
END using ODE-45
2. Matlab code
Brief discussion of code
I firstly defined my constants so that matlab would know what i mean by k1, k2, k3
without constantly writing the values of the constants. Then I added a time span so that
matlab would know the time range to run my code for. I then created vectors of initial
concentrations as this is given and needed to solve the ODEs. from this, i could then
solve the ODEs using ODE-45 function
A full description of my code is listed in the appendix.

3. Using simulink to solve ODEs

This is the diagram produced in the scope once I ran the simulink code

4.Main learning outcomes


● I have learned how to use matlab and be specific whilst coding
● I have learned how to use simulink to solve ODEs
● I have learned which simulink models to use to get my desired outcome for example
using scope to view my diagram and using a MUX to combine my separate ODEs into 1
diagram
● This assignment has taught me how to fix my code on matlab and simulink where errors
may have occurred
● I have learned to use the ODE-45 function to solve ODEs

Appendix

%% defining constants global


global k1 k2 k3
k1 = 0.4526;
k2 = 0.3958;
k3 = 0.3523;
%% setting a vector of the initial conditions
conc0 = [3, 1, 0, 0, 0, 0];
%% setting the integration time span
TSpan = [0 100];
%% solving ODEs
[tout, conc] = ode45('bioreactionODE', TSpan, conc0);
%% plotting the graph
plot(tout, conc)
xlabel ('time')
ylabel ('concentration')
legend ('[MeOH]', '[TG]', '[BD]', '[DG]', '[MG]', '[GL]');

function [dconcdt] = bioreactionODE(t,conc)


%% defining constants
global k1 k2 k3
%% assigning numbers to the concentration species
MeOH = conc(1);
TG = conc(2);
BD = conc(3);
DG = conc(4);
MG = conc(5);
GL = conc(6);
%% defining the rate equations
r1 = k1*MeOH*TG
r2 = k2*MeOH*DG
r3 = k3*MeOH*MG
%% defining ODEs
dMeOHdt = -r1 - r2 - r3;
dTGdt = -r1;
dBDdt = r1 + r2 + r3;
dDGdt = r1 - r2;
dMGdt = r2 - r3;
dGLdt = r3;
dconcdt = [dMeOHdt; dTGdt; dBDdt; dDGdt; dMGdt; dGLdt]
end

You might also like