12.07.2015 Views

What Is Optimization Toolbox?

What Is Optimization Toolbox?

What Is Optimization Toolbox?

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2 Tutorialeither) then, in this problem nlsfs1, the finite-differencing code attempts tocompute all 1000-by-1000 entries in the Jacobian. But in this case there areonly 2998 nonzeros, substantially less than the 1,000,000 possible nonzerosthe finite-differencing code attempts to compute. In other words, this problemis solvable if you provide the sparsity pattern. If not, most computers run outof memory when the full dense finite-differencing is attempted. On mostsmall problems, it is not essential to provide the sparsity structure.SupposethesparsematrixJstr, computed previously, has been saved in filenlsdat1.mat. The following driver calls fsolve applied to nlsf1a, whichisthesameasnlsf1 except that only the function values are returned; sparsefinite-differencing is used to estimate the sparse Jacobian matrix as needed.Step 1: Write an M-file nlsf1a.m that computes the objectivefunction values.function F = nlsf1a(x);% Evaluate the vector functionn = length(x);F = zeros(n,1);i = 2:(n-1);F(i) = (3-2*x(i)).*x(i)-x(i-1)-2*x(i+1) + 1;F(n) = (3-2*x(n)).*x(n)-x(n-1) + 1;F(1) = (3-2*x(1)).*x(1)-2*x(2) + 1;Step 2: Call the system of equations solve routine.xstart = -ones(1000,1);fun = @nlsf1a;load nlsdat1 % Get Jstroptions = optimset('Display','iter','JacobPattern',Jstr,...'LargeScale','on','PrecondBandWidth',1);[x,fval,exitflag,output] = fsolve(fun,xstart,options);In this case, the output displayed isNorm of First-order CG-Iteration Func-count f(x) step optimality Iterations1 6 1011 1 19 02 11 16.0839 7.92496 1.92 12-48

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!