ChBE 2120 Homework 7, Spring 2011
Due: Friday, March 11, at 8:05 AM
1)
We will begin by continuing where Homework 6 left off.
For
the following function:
݃ሺݔ, ݕሻ ൌ െ4ݔ
ଶ
2ݔݕ െ ݕ
ଶ
You already have a Matlab function that represents the function above, named
hw6funcG_myGtAccountId.m
.
a)
Begin by remaking the contour plot from the last assignment.
In a script named
hw7_myGtAccountId.m
script, plot the function using the Matlab command contour, for 2
< x < 2 and 2 < y < 2.
You will need this figure later.
Hint: use the following snippet of code as
the basis for your code to make your contour plot:
[xMesh,yMesh] = meshgrid(xRange,yRange);
gMat = hw6funcG_mstyczynski6(xMesh,yMesh);
[c,h] = contour(xMesh,yMesh,gMat,10);
clabel(c,h)
b)
In your
hw7
script, perform two full steps of the univariate search method (discussed on
Wednesday) to find the value of (x,y) that maximizes this function, and the function’s value at
that (x,y).
The univariate method works by searching in one direction at a time: you hold one
variable constant and optimize on the other.
We will do this in MATLAB by “parameterizing”
our function.
(For more details on this, search for “Passing extra parameters” in the Matlab
interactive help.)
What we will do is first choose an initial x value: 1.2.
We will optimize our
function for y, with x set to 1.2, and use our Golden Section search from the previous assignment
with the limits equal to [2, 2].
We do this by parameterizing our function… we cannot pass
@hw6funcG_myGtAccountId to our Golden Section function, because the Golden Section
expects only one variable in the function, and we have two.
So, parameterizing means passing
the following to the Golden Section search as the “function”:
@(y) hw6funcG_mstyczynski6(initialX,y)
This means that we are passing a function handle (signified by the @ sign), but it will only be a
function in one variable (indicated by the y in parentheses after the @ sign).
The function we are
passing is based on our hw6 function, but using a constant value in the x location (in our case, set
to initialX, which we would have defined in a prior line as equal to 1.2).
So, in total, our line of
code would look something like this:
firstY = goldenSectionMax_mstyczynski6(@(y) ...
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '07
 Gallivan
 Calculus, Derivative, Optimization, Golden section search

Click to edit the document details