3294
|
1 @c Copyright (C) 1996, 1997 John W. Eaton |
|
2 @c This is part of the Octave manual. |
|
3 @c For copying conditions, see the file gpl.texi. |
|
4 |
4167
|
5 @node Nonlinear Equations |
3294
|
6 @chapter Nonlinear Equations |
|
7 @cindex nonlinear equations |
|
8 @cindex equations, nonlinear |
|
9 |
|
10 Octave can solve sets of nonlinear equations of the form |
|
11 @iftex |
|
12 @tex |
|
13 $$ |
|
14 f (x) = 0 |
|
15 $$ |
|
16 @end tex |
|
17 @end iftex |
|
18 @ifinfo |
|
19 |
|
20 @example |
|
21 F (x) = 0 |
|
22 @end example |
|
23 @end ifinfo |
|
24 |
|
25 @noindent |
|
26 using the function @code{fsolve}, which is based on the @sc{Minpack} |
|
27 subroutine @code{hybrd}. |
|
28 |
3368
|
29 @DOCSTRING(fsolve) |
3294
|
30 |
3368
|
31 @DOCSTRING(fsolve_options) |
3294
|
32 |
|
33 Here is a complete example. To solve the set of equations |
|
34 @iftex |
|
35 @tex |
|
36 $$ |
|
37 \eqalign{-2x^2 + 3xy + 4\sin(y) - 6 &= 0\cr |
|
38 3x^2 - 2xy^2 + 3\cos(x) + 4 &= 0} |
|
39 $$ |
|
40 @end tex |
|
41 @end iftex |
|
42 @ifinfo |
|
43 |
|
44 @example |
|
45 -2x^2 + 3xy + 4 sin(y) = 6 |
|
46 3x^2 - 2xy^2 + 3 cos(x) = -4 |
|
47 @end example |
|
48 @end ifinfo |
|
49 |
|
50 @noindent |
|
51 you first need to write a function to compute the value of the given |
|
52 function. For example: |
|
53 |
|
54 @example |
|
55 function y = f (x) |
|
56 y(1) = -2*x(1)^2 + 3*x(1)*x(2) + 4*sin(x(2)) - 6; |
|
57 y(2) = 3*x(1)^2 - 2*x(1)*x(2)^2 + 3*cos(x(1)) + 4; |
|
58 endfunction |
|
59 @end example |
|
60 |
|
61 Then, call @code{fsolve} with a specified initial condition to find the |
|
62 roots of the system of equations. For example, given the function |
|
63 @code{f} defined above, |
|
64 |
|
65 @example |
|
66 [x, info] = fsolve ("f", [1; 2]) |
|
67 @end example |
|
68 |
|
69 @noindent |
|
70 results in the solution |
|
71 |
|
72 @example |
|
73 x = |
|
74 |
|
75 0.57983 |
|
76 2.54621 |
|
77 |
|
78 info = 1 |
|
79 @end example |
|
80 |
|
81 A value of @code{info = 1} indicates that the solution has converged. |
|
82 |
|
83 The function @code{perror} may be used to print English messages |
|
84 corresponding to the numeric error codes. For example, |
|
85 |
|
86 @example |
|
87 @group |
|
88 perror ("fsolve", 1) |
|
89 @print{} solution converged to requested tolerance |
|
90 @end group |
|
91 @end example |
|
92 |
|
93 |