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 111 112 113 114 115 116 117 118 119 120 121
|
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
from ./octave.texi on 18 June 1999 -->
<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="IDX741"></A>
<A NAME="IDX742"></A>
</P>
<P>
Octave can solve sets of nonlinear equations of the form
</P>
<PRE>
F (x) = 0
</PRE>
<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="IDX743"></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="IDX744"></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>
<PRE>
-2x^2 + 3xy + 4 sin(y) = 6
3x^2 - 2xy^2 + 3 cos(x) = -4
</PRE>
<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>
|