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.

Large-Scale ExamplesNonlinear Equations with JacobianConsider the problem of finding a solution to a system of nonlinear equationswhose Jacobian is sparse. The dimension of the problem in this exampleis 1000. The goal is to find x such that F(x) =0. Assumingn = 1000, thenonlinear equations areTo solve a large nonlinear system of equations, F(x) = 0, use the large-scalemethod available in fsolve.Step 1: Write an M-file nlsf1.m that computes the objectivefunction values and the Jacobian.function [F,J] = nlsf1(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+ 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;% Evaluate the Jacobian if nargout > 1if nargout > 1d = -4*x + 3*ones(n,1); D = sparse(1:n,1:n,d,n,n);c = -2*ones(n-1,1); C = sparse(1:n-1,2:n,c,n,n);e = -ones(n-1,1); E = sparse(2:n,1:n-1,e,n,n);J = C + D + E;endStep 2: Call the solve routine for the system of equations.xstart = -ones(1000,1);fun = @nlsf1;options =2-45

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

Saved successfully!

Ooh no, something went wrong!