Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.1 - English

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilab Help >> Elementary Functions > Discrete mathematics > rat

rat

Floating point rational approximation

Syntax

[N,D]=rat(X [,tol])
Y=rat(X [,tol])

Arguments

X

real vector or matrix

tol

real positive scalar, the tolerance (see below). Default value is 1d-6.

N

integer vector or matrix

D

integer vector or matrix

Y

real vector or matrix

Description

[N,D] = rat(X,tol) returns two integer matrices so that N./D is close toX in the sense that abs(N./D - X) <= tol*norm(X,1)*abs(X).

y=rat(x,tol) return the quotient N./D

The rational approximations are generated by truncating continued fraction expansions.

Examples

[n,d]=rat([3.5, 1.333333,-0.8])
[n,d]=rat(%pi)
[n,d]=rat(%pi,1.d-12)
n/d-%pi

See also

  • int — round towards zero
  • round — round to nearest integer
Report an issue
<< primes Discrete mathematics Matrix generation >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jan 03 14:23:23 CET 2022