[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why is 2/3 not seen as rational? [was "plotting even function"]
From: |
Mike Miller |
Subject: |
Re: Why is 2/3 not seen as rational? [was "plotting even function"] |
Date: |
Mon, 21 Mar 2005 08:51:53 -0600 (CST) |
On Mon, 21 Mar 2005, Paul Kienzle wrote:
The cubed root function is multi-valued and Octave is choosing a
different root than you expect. Look at -8 for example:
x^3 + 8 has three roots:
octave> roots([1,0,0,8])
ans =
-2.0000 + 0.0000i
1.0000 + 1.7321i
1.0000 - 1.7321i
Octave chooses one of them:
octave> (-8).^(1/3)
ans = 1.0000 + 1.7321i
It seems to 'choose' using De Moivre's theorem.
For x > 0 and integer n != 0:
-x = x * (cos(pi) + sin(pi)*i)
(-x)^(1/n) = x^(1/n)*(cos(pi/n)+sin(pi/n)*i)
As someone else pointed out, the abs function will force the answer to be
a real integer:
- Mapping Function: abs (Z)
Compute the magnitude of Z, defined as |Z| = `sqrt (x^2 + y^2)'.
For example,
abs (3 + 4i)
=> 5
So, for x > 0 and integer n != 0,
-abs((-x)^(1/n))
seems to give the desired answer when n is odd, but that isn't very
helpful because -(x)^(1/n) gives the same answer when n is odd.
On the other hand, this seems to do what the guy originally wanted (for
scalar integer values of a and b and any real-valued x vector.):
abs(rem(a,2))*abs(rem(b,2))*sign(x).*(abs(x).^(a/b)) +
(1-abs(rem(a,2)))*abs(x).^(a/b) + abs(rem(a,2))*(1-abs(rem(b,2)))*x.^(a/b)
Mike
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------