File: Finding-Roots.html

package info (click to toggle)
octave3.2 3.2.4-8
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 62,936 kB
  • ctags: 37,353
  • sloc: cpp: 219,497; fortran: 116,336; ansic: 10,264; sh: 5,508; makefile: 4,245; lex: 3,573; yacc: 3,062; objc: 2,042; lisp: 1,692; awk: 860; perl: 844
file content (135 lines) | stat: -rw-r--r-- 6,827 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<html lang="en">
<head>
<title>Finding Roots - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Polynomial-Manipulations.html#Polynomial-Manipulations" title="Polynomial Manipulations">
<link rel="prev" href="Evaluating-Polynomials.html#Evaluating-Polynomials" title="Evaluating Polynomials">
<link rel="next" href="Products-of-Polynomials.html#Products-of-Polynomials" title="Products of Polynomials">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Finding-Roots"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="Products-of-Polynomials.html#Products-of-Polynomials">Products of Polynomials</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Evaluating-Polynomials.html#Evaluating-Polynomials">Evaluating Polynomials</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Polynomial-Manipulations.html#Polynomial-Manipulations">Polynomial Manipulations</a>
<hr>
</div>

<h3 class="section">27.2 Finding Roots</h3>

<p>Octave can find the roots of a given polynomial.  This is done by computing
the companion matrix of the polynomial (see the <code>compan</code> function
for a definition), and then finding its eigenvalues.

<!-- ./polynomial/roots.m -->
   <p><a name="doc_002droots"></a>

<div class="defun">
&mdash; Function File:  <b>roots</b> (<var>v</var>)<var><a name="index-roots-2026"></a></var><br>
<blockquote>
        <p>For a vector <var>v</var> with N components, return
the roots of the polynomial

     <pre class="example">          v(1) * z^(N-1) + ... + v(N-1) * z + v(N)
</pre>
        <p>As an example, the following code finds the roots of the quadratic
polynomial
     <pre class="example">          p(x) = x^2 - 5.
</pre>
        <pre class="example">          c = [1, 0, -5];
          roots(c)
            2.2361
           -2.2361
</pre>
        <p>Note that the true result is
+/- sqrt(5)
which is roughly
+/- 2.2361. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dcompan.html#doc_002dcompan">compan</a>. 
</p></blockquote></div>

<!-- ./polynomial/compan.m -->
   <p><a name="doc_002dcompan"></a>

<div class="defun">
&mdash; Function File:  <b>compan</b> (<var>c</var>)<var><a name="index-compan-2027"></a></var><br>
<blockquote><p>Compute the companion matrix corresponding to polynomial coefficient
vector <var>c</var>.

        <p>The companion matrix is

     <!-- Set example in small font to prevent overfull line -->
     <pre class="smallexample">               _                                                        _
              |  -c(2)/c(1)   -c(3)/c(1)  ...  -c(N)/c(1)  -c(N+1)/c(1)  |
              |       1            0      ...       0             0      |
              |       0            1      ...       0             0      |
          A = |       .            .   .            .             .      |
              |       .            .       .        .             .      |
              |       .            .           .    .             .      |
              |_      0            0      ...       1             0     _|
</pre>
        <p>The eigenvalues of the companion matrix are equal to the roots of the
polynomial. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dpoly.html#doc_002dpoly">poly</a>, <a href="doc_002droots.html#doc_002droots">roots</a>, <a href="doc_002dresidue.html#doc_002dresidue">residue</a>, <a href="doc_002dconv.html#doc_002dconv">conv</a>, <a href="doc_002ddeconv.html#doc_002ddeconv">deconv</a>, <a href="doc_002dpolyval.html#doc_002dpolyval">polyval</a>, <a href="doc_002dpolyderiv.html#doc_002dpolyderiv">polyderiv</a>, <a href="doc_002dpolyinteg.html#doc_002dpolyinteg">polyinteg</a>. 
</p></blockquote></div>

<!-- ./polynomial/mpoles.m -->
   <p><a name="doc_002dmpoles"></a>

<div class="defun">
&mdash; Function File: [<var>multp</var>, <var>indx</var>] = <b>mpoles</b> (<var>p</var>)<var><a name="index-mpoles-2028"></a></var><br>
&mdash; Function File: [<var>multp</var>, <var>indx</var>] = <b>mpoles</b> (<var>p, tol</var>)<var><a name="index-mpoles-2029"></a></var><br>
&mdash; Function File: [<var>multp</var>, <var>indx</var>] = <b>mpoles</b> (<var>p, tol, reorder</var>)<var><a name="index-mpoles-2030"></a></var><br>
<blockquote><p>Identify unique poles in <var>p</var> and associates their multiplicity,
ordering them from largest to smallest.

        <p>If the relative difference of the poles is less than <var>tol</var>, then
they are considered to be multiples.  The default value for <var>tol</var>
is 0.001.

        <p>If the optional parameter <var>reorder</var> is zero, poles are not sorted.

        <p>The value <var>multp</var> is a vector specifying the multiplicity of the
poles.  <var>multp</var>(:) refers to multiplicity of <var>p</var>(<var>indx</var>(:)).

        <p>For example,

     <pre class="example">          p = [2 3 1 1 2];
          [m, n] = mpoles(p);
             m = [1; 1; 2; 1; 2]
             n = [2; 5; 1; 4; 3]
             p(n) = [3, 2, 2, 1, 1]
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dpoly.html#doc_002dpoly">poly</a>, <a href="doc_002droots.html#doc_002droots">roots</a>, <a href="doc_002dconv.html#doc_002dconv">conv</a>, <a href="doc_002ddeconv.html#doc_002ddeconv">deconv</a>, <a href="doc_002dpolyval.html#doc_002dpolyval">polyval</a>, <a href="doc_002dpolyderiv.html#doc_002dpolyderiv">polyderiv</a>, <a href="doc_002dpolyinteg.html#doc_002dpolyinteg">polyinteg</a>, <a href="doc_002dresidue.html#doc_002dresidue">residue</a>. 
</p></blockquote></div>

   </body></html>