help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rat function


From: CdeMills
Subject: Re: rat function
Date: Tue, 17 Apr 2012 06:14:10 -0700 (PDT)

rikydzee wrote
> 
> Hello guys, i'm new to octave and i need some help.
> I have a vector of double like A=[ 4.3, 5.7 ,3.1] and i want to aproximate
> the elements of A, then A will be 4 6, 3 .  I found the rat function , if
> i type x=rat(A(2),5) it returns '6', but this '6' is not a number. If i
> type x+1  it returns a matrix. Can anyone help me? I really need this for
> a homework.
> 
> P.S: Sorry for my bad english
> 

rat returns a rational approximation, that is, given some number X, it
returns A and B such that abs(x-A/B) < tol; where tol is some small number.
When called without argument, as you do, it diplays something called
continued fraction expansion, which is a char array. Incrementing it results
indeed in a matrix, as you are mixing chars and integer.

In your case, if you need approximating by integer values, the function to
use are
- round (to the nearest integer)
- floor (rounds towards minus inf)
- fix (remove the fractional part; rounds towards zero)
- ceil (tounds towards plus inf)

Pascal


--
View this message in context: 
http://octave.1599824.n4.nabble.com/rat-function-tp4564616p4564683.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]