sol_hw4 - CE 335 Solutions to Homework 4 11 function[x fx...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CE 335 Solutions to Homework 4 11) function [x, fx, ea, iter] = goldmax(f, xl, xu, es, maxit, varargin) % goldmax: maximization golden section search % arguments same as for goldmin function in book if nargin < 3, error('at least 3 arguments required'), end if nargin < 4 || isempty(es), es = 1E-4;, end if nargin < 5 || isempty(maxit), maxit = 50;, end phi = (1 + sqrt(5)) / 2; iter = 0; while (1) d = (phi - 1) * (xu - xl); x1 = xl + d; x2 = xu - d; if f(x1, varargin{:}) > f(x2, varargin{:}) %only change needed from goldmin: < becomes > xopt = x1; xl = x2; else xopt = x2; xu = x1; end iter = iter + 1; ea = (2 - phi) * abs((xu - xl) / xopt); if ea <= es || iter >= maxit break end end x = xopt; fx = f(xopt, varargin{:}); To test this function: g = 9.81; z0 = 100; v0 = 55; m = 80;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
c = 15; z = @(t) z0 + (m/c)*(v0 + m*g/c)*(1 - exp(-c*t/m)) - m*g*t/c; [t_max, z_max, ea, iter] = goldmax(z, 0, 10) %from Figure 7.1, the function is unimodal, and the maximum elevation is 150-200 m at about 4 s >> t_max =
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/30/2011 for the course CGN 3350 taught by Professor Lybas during the Spring '11 term at University of Florida.

Page1 / 4

sol_hw4 - CE 335 Solutions to Homework 4 11 function[x fx...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online