Mercurial > hg > octave-shane
changeset 11406:a7e73f903ea6
nonlin.txi: correct docs for using Jacobian with fsolve
author | Tatsuro Matsuoka <tmacchant@yahoo.co.jp> |
---|---|
date | Wed, 22 Dec 2010 03:59:59 -0500 |
parents | 51b6193e90bb |
children | ed827ffa5a43 |
files | doc/ChangeLog doc/interpreter/nonlin.txi |
diffstat | 2 files changed, 17 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2010-12-22 Tatsuro Matsuoka <tmacchant@yahoo.co.jp> + + * nonlin.txi: Correct docs for using Jacobian with fsolve. + 2010-12-22 Judd Storrs <jstorrs@gmail.com> * interpreter/expr.txi: Insert operator function docstrings.
--- a/doc/interpreter/nonlin.txi +++ b/doc/interpreter/nonlin.txi @@ -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