BME203 Numerical Methods

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

BME 203

Biomedical Modelling and Numerical Methods

Instructor: G. K. German
Department of Biomedical Engineering
Office: BI2609
Email: [email protected]
Teaching Assistant: Yizhong Liu

Optimization

Optimization is the process of creating something that is


effective as possible.
As engineers, we strive to design products that are always
confronting optimization problems for a minimum of cost.
Optimization problems include
Minimzing the weight and maximizing the energy dissipation of
helmets
Minimizing the free energy of systems
Maximizing the printing and curing rates of bioprinters

Mathematically optimization deals with finding maxima and


minima of a function that depends on 1 or more variables.
Goal is determine the values of the variables that yield
maxima or minima for that function
These can then be substituted in to the function to compute
optimal values

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

Method 1: Optimum Analytical


Solution by Root Finding
Consider the trajectory of a projectile

Method 1: Optimum Analytical


Solution by Root Finding
In order to establish its maximum height, we can find the
where the derivative is equal to zero

We know initial parameters v, and g, so we solve for x


Plug x back into our original equation and we obtain maximum
y

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,

g, will vary with the food

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

We wish to find the optimal food concentration

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

Function has a minimum of f(x1,x2)~0 at x1 = -1 and x2 = 1.5

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

You might also like