help-octave
[Top][All Lists]
Advanced

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

Re: plotting even function


From: Geraint Paul Bevan
Subject: Re: plotting even function
Date: Mon, 21 Mar 2005 00:46:37 +0000
User-agent: Mozilla Thunderbird 0.5 (X11/20040306)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Henry F. Mollet wrote:
> x1 = 0.50000
> octave:23> x1^(1/3)
> ans = 0.79370
> octave:24> x2=-0.5
> x2 = -0.50000
> octave:25> x2^(1/3)
> ans = 0.39685 + 0.68736i
> octave:26> abs(ans)
> ans = 0.79370
> Will the above work?
> Henry
>

It finds the correct magnitude but the sign is wrong for negative x so
it must be multiplied by sign(x).

octave> function y = cbrt (x)
> y = sign(x) .* (abs(x).^(1/3));
> endfunction

octave> cbrt([-8,-64,8])
ans =

  -2.0000  -4.0000   2.0000

- --
Geraint Bevan
http://homepage.ntlworld.com/geraint.bevan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iEYEARECAAYFAkI+GW0ACgkQcXV3N50QmNObQQCbB2n+u8KJ97ic0r4qgL6Jlkw3
jmgAnjRqOPW+9z+MrPFF0AzriRPEEMFo
=ifuW
-----END PGP SIGNATURE-----



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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