File: octave_19.html

package info (click to toggle)
octave 2.0.13.95-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 26,052 kB
  • ctags: 16,420
  • sloc: cpp: 67,184; fortran: 41,514; ansic: 26,607; sh: 7,291; makefile: 4,089; lex: 1,961; yacc: 1,852; perl: 1,676; lisp: 1,664; exp: 123
file content (110 lines) | stat: -rw-r--r-- 2,758 bytes parent folder | download
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
104
105
106
107
108
109
110
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
     from ./octave.texi on 9 October 1998 -->

<TITLE>GNU Octave - Nonlinear Equations</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="octave_1.html">first</A>, <A HREF="octave_18.html">previous</A>, <A HREF="octave_20.html">next</A>, <A HREF="octave_40.html">last</A> section, <A HREF="octave_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC147" HREF="octave_toc.html#TOC147">Nonlinear Equations</A></H1>
<P>
<A NAME="IDX737"></A>
<A NAME="IDX738"></A>

</P>
<P>
Octave can solve sets of nonlinear equations of the form

</P>
<P>
using the function <CODE>fsolve</CODE>, which is based on the MINPACK
subroutine <CODE>hybrd</CODE>.

</P>
<P>
<DL>
<DT><U>Loadable Function:</U> [<VAR>x</VAR>, <VAR>info</VAR>] = <B>fsolve</B> <I>(<VAR>fcn</VAR>, <VAR>x0</VAR>)</I>
<DD><A NAME="IDX739"></A>
Given <VAR>fcn</VAR>, the name of a function of the form <CODE>f (<VAR>x</VAR>)</CODE>
and an initial starting point <VAR>x0</VAR>, <CODE>fsolve</CODE> solves the set of
equations such that <CODE>f(<VAR>x</VAR>) == 0</CODE>.
</DL>

</P>
<P>
<DL>
<DT><U>Loadable Function:</U>  <B>fsolve_options</B> <I>(<VAR>opt</VAR>, <VAR>val</VAR>)</I>
<DD><A NAME="IDX740"></A>
When called with two arguments, this function allows you set options
parameters for the function <CODE>fsolve</CODE>.  Given one argument,
<CODE>fsolve_options</CODE> 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.
</DL>

</P>
<P>
Here is a complete example.  To solve the set of equations

</P>
<P>
you first need to write a function to compute the value of the given
function.  For example:

</P>

<PRE>
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
</PRE>

<P>
Then, call <CODE>fsolve</CODE> with a specified initial condition to find the
roots of the system of equations.  For example, given the function
<CODE>f</CODE> defined above,

</P>

<PRE>
[x, info] = fsolve ("f", [1; 2])
</PRE>

<P>
results in the solution

</P>

<PRE>
x =

  0.57983
  2.54621

info = 1
</PRE>

<P>
A value of <CODE>info = 1</CODE> indicates that the solution has converged.

</P>
<P>
The function <CODE>perror</CODE> may be used to print English messages
corresponding to the numeric error codes.  For example,

</P>

<PRE>
perror ("fsolve", 1)
     -| solution converged to requested tolerance
</PRE>

<P><HR><P>
Go to the <A HREF="octave_1.html">first</A>, <A HREF="octave_18.html">previous</A>, <A HREF="octave_20.html">next</A>, <A HREF="octave_40.html">last</A> section, <A HREF="octave_toc.html">table of contents</A>.
</BODY>
</HTML>