ChBE 2120 Homework 7, Spring 2011
Due: Friday, March 11, at 8:05 AM
We will begin by continuing where Homework 6 left off.
the following function:
You already have a Matlab function that represents the function above, named
Begin by re-making the contour plot from the last assignment.
In a script named
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);
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
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”
(For more details on this, search for “Passing extra parameters” in the Matlab
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”:
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) .