1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
@c Copyright (C) 1996, 1997 John W. Eaton
@c This is part of the Octave manual.
@c For copying conditions, see the file gpl.texi.
@node Nonlinear Equations, Quadrature, Linear Algebra, Top
@chapter Nonlinear Equations
@cindex nonlinear equations
@cindex equations, nonlinear
Octave can solve sets of nonlinear equations of the form
@iftex
@tex
$$
f (x) = 0
$$
@end tex
@end iftex
@ifinfo
@example
F (x) = 0
@end example
@end ifinfo
@noindent
using the function @code{fsolve}, which is based on the @sc{Minpack}
subroutine @code{hybrd}.
@deftypefn {Loadable Function} {[@var{x}, @var{info}] =} fsolve (@var{fcn}, @var{x0})
Given @var{fcn}, the name of a function of the form @code{f (@var{x})}
and an initial starting point @var{x0}, @code{fsolve} solves the set of
equations such that @code{f(@var{x}) == 0}.
@end deftypefn
@deftypefn {Loadable Function} {} fsolve_options (@var{opt}, @var{val})
When called with two arguments, this function allows you set options
parameters for the function @code{fsolve}. Given one argument,
@code{fsolve_options} returns the value of the corresponding option. If
no arguments are supplied, the names of all the available options and
their current values are displayed.
@end deftypefn
Here is a complete example. To solve the set of equations
@iftex
@tex
$$
\eqalign{-2x^2 + 3xy + 4\sin(y) - 6 &= 0\cr
3x^2 - 2xy^2 + 3\cos(x) + 4 &= 0}
$$
@end tex
@end iftex
@ifinfo
@example
-2x^2 + 3xy + 4 sin(y) = 6
3x^2 - 2xy^2 + 3 cos(x) = -4
@end example
@end ifinfo
@noindent
you first need to write a function to compute the value of the given
function. For example:
@example
function y = f (x)
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
@end example
Then, call @code{fsolve} with a specified initial condition to find the
roots of the system of equations. For example, given the function
@code{f} defined above,
@example
[x, info] = fsolve ("f", [1; 2])
@end example
@noindent
results in the solution
@example
x =
0.57983
2.54621
info = 1
@end example
A value of @code{info = 1} indicates that the solution has converged.
The function @code{perror} may be used to print English messages
corresponding to the numeric error codes. For example,
@example
@group
perror ("fsolve", 1)
@print{} solution converged to requested tolerance
@end group
@end example
|