BME203 Numerical Methods
BME203 Numerical Methods
BME203 Numerical Methods
Instructor: G. K. German
Department of Biomedical Engineering
Office: BI2609
Email: [email protected]
Teaching Assistant: Yizhong Liu
Optimization
Optimization
Sometimes maxima/minima can be obtained analytically
But this only works for simple models
For more complex models, the math becomes much too
complicated. Then you turn to numerical methods of solving
the equations.
Solution method is similar in spirit to root finding. We make
guesses in order to search for a point on a function.
Root location involves searching for the location where
function is zero.
In contrast, optimization involves searching for the functions
extreme points
One Dimensional
Optimization
This is used when you need to find the minimum r
maximum of a funcion of a single variable
While the trajectory problem has only 1 maximum,
often a function can have multiple maxima and
minima
Global max
Local max
Local min
Global min
One Dimensional
Optimization
A global optimum represents the best solution
A local optimum, thought not the very best, is better
than immediate neighbours
Global max
Local max
Local min
Global min
fminbnd
The good news is that you dont have to do all of that
maths.
fminbnd is similar to fzero, but finds the minimum of
a single-variable function on fixed interval
It does so using a combination of bracketing
techniques and parabolic optimization
It has not opposite (i.e. no fmaxbnd) because it is not
needed
To solve for a maximum of f(x) is the same as
solving for the minimum of f(x)
Case-Study-Yeast.m +Notes
Case study
Class exercise
We need to optimize the growth rate of yeast that produces
an antibiotic
The growth rate of yeast,
concentration, c
As c0: THe yeast have no food, so will not grow
As c large values, the growth rate of yeast will also tend to
zero because the food has a toxic effect on the
microorganism
Case study
g(c)
[per
day]
c [mg/L)
Use fminbnd to calculate optimal food concentration
fminbnd structure
g = @(c) x^2+x+5
Define handle and equation
[cpeak,gpeak] = fminbnd(g,lowerbound,upperbound)
Try obtaining a peak for lower and upper bounds of 0 and
10
Multidimensional Optimization
How do we find the minimum/maximum of a system with 2 or more
variables?
-Multi-dimensional-function.m
x=linspace(-2,0,40);
y=linspace(0,3,40);
[X,Y] = meshgrid(x,y)
Z=2+X-Y+(2*X.^2) + (2*X.*Y) + (Y.^2);
subplot(1,2,1)
cs=contour(X,Y,Z);clabel(cs)
xlabel('x_1');ylabel('x_2')
title('(a) Contour plot');grid on
subplot(1,2,2)
cs=surfc(X,Y,Z)
zmin=floor(min(Z))
zmax = ceil(max(Z))
xlabel('x_1');ylabel('x_2');zlabel('f(x_1,x_2)')
Multidimensional Optimization
Answer 1: Graphically
Multidimensional Optimization
Answer 2: Using fminsearch
[xmin, fval] = fminsearch(function,x0)
function is usually written
function = @(x) 2+x(1)-x(2)+(2*x(1)^2)+(2*x(1)*x(2))+(x(2)^2)
Note that x(1) and x(2) are 2 variables
x0 is the initial guess
Given that you have 2 variables, then x0 will need to be a vector
i.e. x0=[guess x(1), guess(x2)]
fval will provide the minimum of f(x1,x2)
xmin will give the x1 and x2 location of the minimum