|
|
| 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 at files@mathworks.com