# HG changeset patch # User Tatsuro Matsuoka # Date 1293008399 18000 # Node ID a7e73f903ea683d8bd722865e130818f74fce5ba # Parent 51b6193e90bb52d30dcec0cbd17f0258c4e6577a nonlin.txi: correct docs for using Jacobian with fsolve diff -r 51b6193e90bb -r a7e73f903ea6 doc/ChangeLog --- a/doc/ChangeLog Wed Dec 22 03:53:39 2010 -0500 +++ b/doc/ChangeLog Wed Dec 22 03:59:59 2010 -0500 @@ -1,3 +1,7 @@ +2010-12-22 Tatsuro Matsuoka + + * nonlin.txi: Correct docs for using Jacobian with fsolve. + 2010-12-22 Judd Storrs * interpreter/expr.txi: Insert operator function docstrings. diff -r 51b6193e90bb -r a7e73f903ea6 doc/interpreter/nonlin.txi --- a/doc/interpreter/nonlin.txi Wed Dec 22 03:53:39 2010 -0500 +++ b/doc/interpreter/nonlin.txi Wed Dec 22 03:59:59 2010 -0500 @@ -68,6 +68,7 @@ @example @group function y = f (x) + y = zeros (2, 1); y(1) = -2*x(1)^2 + 3*x(1)*x(2) + 4*sin(x(2)) - 6; y(2) = 3*x(1)^2 - 2*x(1)*x(2)^2 + 3*cos(x(1)) + 4; endfunction @@ -137,11 +138,17 @@ @example @group -function J = jacobian(x) - J(1,1) = 3*x(2) - 4*x(1); - J(1,2) = 4*cos(x(2)) + 3*x(1); - J(2,1) = -2*x(2)^2 - 3*sin(x(1)) + 6*x(1); - J(2,2) = -4*x(1)*x(2); +function [y, jac] = f (x) + y = zeros (2, 1); + y(1) = -2*x(1)^2 + 3*x(1)*x(2) + 4*sin(x(2)) - 6; + y(2) = 3*x(1)^2 - 2*x(1)*x(2)^2 + 3*cos(x(1)) + 4; + if (nargout == 2) + jac = zeros (2, 2); + jac(1,1) = 3*x(2) - 4*x(1); + jac(1,2) = 4*cos(x(2)) + 3*x(1); + jac(2,1) = -2*x(2)^2 - 3*sin(x(1)) + 6*x(1); + jac(2,2) = -4*x(1)*x(2); + endif endfunction @end group @end example @@ -150,7 +157,7 @@ The Jacobian can then be used with the following call to @code{fsolve}: @example -[x, fval, info] = fsolve (@{@@f, @@jacobian@}, [1; 2]); +[x, fval, info] = fsolve (@@f, [1; 2], optimset ("jacobian", "on")); @end example @noindent