Tips & Tricks: Getting started using optimization with MATLAB
27 Aug 2008
(Updated 27 Aug 2008)
Demo files from the August 21, 2008 Webinar
function c = nestedOptimExample()
t = [0 .3 .8 1.1 1.6 2.3]';
y = [.82 .72 .63 .60 .55 .50]';
% Curve fitting (Optimization routine)
c = lsqnonlin( @myNestedCurve, [1 1]);
% Objective Function
% Note that t or y are not passed in the function definition
function resid = myNestedCurve(x)
yhat = x(1) + x(2)*exp(-t); % where did t come from?
resid = yhat - y; % where does y come from?
% t and y are defined in the parent function but passed to all
% subfunctions, do not need to pass them explicitly to nested