Code covered by the BSD License  

Highlights from
Tips & Tricks: Getting started using optimization with MATLAB

image thumbnail

Tips & Tricks: Getting started using optimization with MATLAB

by

 

27 Aug 2008 (Updated )

Demo files from the August 21, 2008 Webinar

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

nestedOptimExample()
function c = nestedOptimExample()

% Data
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
        % functions.
    end
end
        

Contact us