Académique Documents
Professionnel Documents
Culture Documents
MATLAB
Contents
Introduction ................................................................................................................... 2
Solving Linear Equations ............................................................................................... 2
Determined linear systems ........................................................................................ 2
Underdetermined equation system............................................................................ 4
Symbolic solution
Introduction
Matlab's strengths include cutting-edge algorithms, enormous data handling abilities, and powerful programming
tools. Matlab was designed for numeric computation, but does include a MUPAD kernel for symbolic computations.
This tool will be unsed in NMST as well as AMN.
x1 + 5 - 2 x2 + x3 = 0
5 x1 - x2 = 0
(1)
3 x3 x1 = 0
This system has three variables (x1. x2, x3) and three equations. Thus, if there is no redundant equation, the system
should have exactly one solution:
x1 = 0.8, x = 4, x3 = 2.2
(2)
How can you use MatLab to find this solution? As being the Matrix Laboratory, linear algebra is a strength of MatLab.
Thus, the system in Eq. (1) is reformulated as matrix operation:
1 2 1 x1 5
5 1
x2 = 0
1
1 x3 3
x
b
A
(3)
Ax = b
(4)
x = A -1b
In this primer no details about the mathematical background are given. Students interested in the mathematics are
referred to an additional document on blackboard, or take a look at standard literature, e.g. Lay, Linear Alegra and its
applications, Addison-Wesley, 1997.
Page 2 of 8
Output:
x=
0.8000
4.0000
2.2000
Page 3 of 8
x1 + 5 - 2 x2 + x3 = 0
5 x1 - x2 = 0
(5)
This system has three variables (x1. x2, x3) and (at least) 1 degree of freedom. Choosing x3 as the independent
variable you can write the solution as:
Lets reformulate that system in matrix notation, using a vector x = (x1, x2, x3) and a matrix A to generate the
equations:
x1
1 2 1 5
x2 =
5 1 0
x3
b
A
x
(6)
1 2 x1 1
5
+ ( x3 ) =
5 1 x 2 0 x
0
f
xd
b
Af
Ad
(7)
x d = A d1 ( b A f x f
(8)
Page 4 of 8
In MatLab:
The result is indeed (0 0) the equations are fulfilled, for all values of x3.
Symbolic solution
For many tasks it is relevant to keep the free variable visible and express the solution as a function of this variable
without entering a value.
MATLAB has an extension called the symbolic toolbox that can express symbolic solutions instead of a numeric
solution. Therefore, the variable that should be treated as symbolic needs to be defined by:
xd =
x3/9 + 5/9
(5*x3)/9 + 25/9
Page 5 of 8
1 2 1
5
x1
5 1
x2 = 0
1
1 3
x3
1
x
3.8
b
A
(9)
Looking at the solution obtained in Eq. (2) you can immediately see, that the last equation x2=3.8 conflicts with the
previous calculation x2=4. The least-square solution is calculated using the standard multiple regression formula (see
explanatory notes in linear regression on how to derive the equation):
1
x = ( AT A ) AT b
(10)
In MatLab:
Page 6 of 8
Exercise 1
3H 5O3
= 12 ,
system. Try to solve the new system numerically and explain the result, even if it fails. Is the
extended system of equations determined now? Explain your calculations.
3 Use the symbolic solution from 3.1 to plot coefficients a (glucose) and e (bicarbonate) as a function of f,
for f values in the interval [1,2]. Label the plot axes and include a legend.
(commands: plot, xlabel, ylabel, legend).
Exercise 2
1 Formulate the charge and element (C, H, O, N, Fe) balances for this reaction and put them into the
matrix-vector form needed for solution with MATLAB. Write and execute the MATLAB script that
solves symbolically the system of equations as a function of coefficient g (for Fe2+).
2 Try to formulate the solution as a function of coefficient a. Explain why it does not work.
3 Use the symbolic solution from 1 to plot coefficients d (O2) and f (water) as a function of g, for g
values in the interval [1,5]. Label the plot axes and include a legend.
(commands: plot, xlabel, ylabel, legend).
Page 7 of 8
Exercise 3:
Task now is to apply this knowledge to find stoichiometric coefficients for the Herbert-Pirt relation based on a series
of steady state experiments from an micro-aerobic ethanol production plant with S. cerevisiae.
Growth rate
D=0.1
D=0.05
D=0.2
D=0.12
D=0.03
0.1
0.05
0.2
0.12
0.03
Substrate uptake
- qS
0.558013
0.349866
0.837589
0.623872
0.23716
Production rate
qP
0.65625
0.4375
0.875
0.715909
0.302885
Tasks
1. The Herbert-Pirt equation reads:
qS = a + b qP + mS
(11)
Ax =b
(12)
Page 8 of 8