%%%%%% Nonlinear Equations with Jacobian %%%%%%%%%%%%%%%%%%%%%%%%% % Solve routine for the system of equations below. Consider the problem of % finding a solution to a system of nonlinear equations whose Jacobian is % sparse. The dimension of the problem in this example is 1000. The goal is % to find x such that F(x) = 0. The nonlinear equations are as follows: % F(1)=3(x_1)-2(x_1)^2-2(x_2)+1 % F(i)=3(x_i)-2(x_i)^2-2(x_i-1)-2(x_i+1)+1 % F(n)=3(x_n)-2(x_n)^2-(x_n-1)+1 % with n = 1000. % To solve a large nonlinear system of equations, F(x)=0, use the % large-scale method available in fsolve. % % See function [F,J] = nleqwj(x); xstart=-ones(1000,1); fun=@nleqwj; options=optimset('Display','iter','LargeScale','on','Jacobian','on'); [x,fval,exitflag,output] = fsolve(fun,xstart,options); % The MathWorks, Matlab7. Copyright (c).