function x = levenberg(f,x1,tol) % LEVENBERG QuasiNewton method for nonlinear systems. % Input: a f objective function Ak = Ak + (yAk*s)*(s'/ts'*s));...
4.7.3 please include code thanks.
A famous result by Kermack and Mckendrick in 1927[37] suggests that in epidemics that kill only a small fraction of a susceptible population, the death rate as a fucntion of time is well modeled by...
- Attachment 1
- Attachment 2
- Attachment 3
function x = levenberg(f,x1,tol)% LEVENBERG Quasi—Newton method for nonlinear systems. % Input: a f objective function Ak = Ak + (y—Ak*s)*(s'/ts'*s)); % x1 initial root approximation jac;is_new = false; % tol stopping tolerance (default is 1e—12) else % don't accept% Output % Get closer to steepest descent. % x array of approximations (one per column) lambda = lambda*4; % Re—initialize the Jacobian if it's out of date.if ~jac_is_new Ak = fdjac(f,x(:,k),fk); jaq_is_new = true; % Operating parameters.if nargin < 3, tol = le-lz; endftol = tol; xtol = tol; maxiter = 49;x = x1(:); fk = f(x1);k = 1; s = Inf;Ak = fdjac(f,x(:,1),fk); % start with FD Jacobianjac_i5_new = true;I = eye(length(x));lambda = 10;while (norm(s) > xtol) && (norm(fk) > ftol) && (k < maxi% Compute the proposed step.B = Ak'tAk + lambdanI;z = Ak'*fk;s = —(B\2);xnew = x(:,k) + s; fnew = f(xnew);% Do we accept the result?if norm(fnew) < norm(fk) % accepty = fnew — fk;x(:,k+1) = xnew; fk = fnew;k = k+1;|lambda = lambda/13; % get closer to Newton% Broyden update of the Jacobian.Ak = Ak + (y—Akas)*(s'l(s'*s));jac_is_new = false; andendend if (norm(fk) > 1e—3)warning('Iteration did not find a root.') end end
Show more