fractions.html

来自「本程序是基于linux系统下c++代码」· HTML 代码 · 共 133 行

HTML
133
字号
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: Rational Approximation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../R.css">
</head><body>

<table width="100%" summary="page for fractions {MASS}"><tr><td>fractions {MASS}</td><td align="right">R Documentation</td></tr></table>
<h2>Rational Approximation</h2>


<h3>Description</h3>

<p>
Find rational approximations to the components of a real numeric
object using a standard continued fraction method.
</p>


<h3>Usage</h3>

<pre>
fractions(x, cycles = 10, max.denominator = 2000, ...)
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>x</code></td>
<td>
Any object of mode numeric. Missing values are now allowed.
</td></tr>
<tr valign="top"><td><code>cycles</code></td>
<td>
The maximum number of steps to be used in the continued fraction
approximation process.
</td></tr>
<tr valign="top"><td><code>max.denominator</code></td>
<td>
An early termination criterion.  If any partial denominator
exceeds <code>max.denominator</code> the continued fraction stops at that point.
</td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
arguments passed to or from other methods.
</td></tr>
</table>

<h3>Details</h3>

<p>
Each component is first expanded in a continued fraction of the
form
</p>
<p>
<code>x = floor(x) + 1/(p1 + 1/(p2 + ...)))</code>
</p>
<p>
where <code>p1</code>, <code>p2</code>, ... are positive integers, terminating either
at <code>cycles</code> terms or when a <code>pj &gt; max.denominator</code>.  The
continued fraction is then re-arranged to retrieve the numerator
and denominator as integers.
</p>
<p>
The numerators and denominators are then combined into a
character vector that becomes the <code>"fracs"</code> attribute and used in
printed representations.
</p>
<p>
Arithmetic operations on <code>"fractions"</code> objects have full floating
point accuracy, but the character representation printed out may
not.
</p>


<h3>Value</h3>

<p>
An object of class <code>"fractions"</code>.  A structure with <code>.Data</code> component
the same as the input numeric <code>x</code>, but with the rational
approximations held as a character vector attribute, <code>"fracs"</code>.
Arithmetic operations on <code>"fractions"</code> objects are possible.</p>

<h3>References</h3>

<p>
Venables, W. N. and Ripley, B. D. (2002)
<EM>Modern Applied Statistics with S.</EM> Fourth Edition. Springer.
</p>


<h3>See Also</h3>

<p>
<code><a href="rational.html">rational</a></code>
</p>


<h3>Examples</h3>

<pre>
X &lt;- matrix(runif(25), 5, 5)
solve(X, X/5)
##              [,1]        [,2]       [,3]        [,4]        [,5]
##  [1,]  2.0000e-01  3.7199e-17 1.2214e-16  5.7887e-17 -8.7841e-17
##  [2,] -1.1473e-16  2.0000e-01 7.0955e-17  2.0300e-17 -1.0566e-16
##  [3,]  2.7975e-16  1.3653e-17 2.0000e-01 -1.3397e-16  1.5577e-16
##  [4,] -2.9196e-16  2.0412e-17 1.5618e-16  2.0000e-01 -2.1921e-16
##  [5,] -3.6476e-17 -3.6430e-17 3.6432e-17  4.7690e-17  2.0000e-01

fractions(solve(X, X/5))
##      [,1] [,2] [,3] [,4] [,5]
## [1,] 1/5    0    0    0    0
## [2,]   0  1/5    0    0    0
## [3,]   0    0  1/5    0    0
## [4,]   0    0    0  1/5    0
## [5,]   0    0    0    0  1/5

fractions(solve(X, X/5)) + 1
##      [,1] [,2] [,3] [,4] [,5]
## [1,] 6/5    1    1    1    1
## [2,]   1  6/5    1    1    1
## [3,]   1    1  6/5    1    1
## [4,]   1    1    1  6/5    1
## [5,]   1    1    1    1  6/5
</pre>



<hr><div align="center">[Package <em>MASS</em> version 7.2-44 <a href="00Index.html">Index]</a></div>

</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?