Board index » delphi » cube roots

cube roots

Can some one please tell me how to calculate a cube root in Pascal? THX.
 

Re:cube roots


In article <31561B82.6...@killroy.seanet.com>,
Harley Bowler  <kill...@killroy.seanet.com> wrote:
:Can some one please tell me how to calculate a cube root in Pascal? THX.

Use the power function which you'll readily find in

 93045 Jan 1 09:31 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
 tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

   All the best, Timo

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
t...@uwasa.fi http://uwasa.fi/~ts BBS 961-3170972; FIN-65101,  Finland

Re:cube roots


Harley Bowler <kill...@killroy.seanet.com> skriver:

Quote
> Can some one please tell me how to calculate a cube root in Pascal? THX.

Exp(X * Ln(a)) returns A^X.

Then use x=1/3 to return the cube root.

Re:cube roots


Quote
On Sun, 24 Mar 1996, Harley Bowler wrote:
> Can some one please tell me how to calculate a cube root in Pascal? THX.

        Well, since there is no exponential function (TP only does
squares and square roots), you would have to create a function that takes
a variable, squares it, and multiplies it by itself.

        a:=sqr(x);
        b:=a*x

will give you a third root.
                                                                Todd

************************************************************************
* Visit my homepage at   http://www.afn.org/~afn32685
* Communication is the difference between a friend and an acquaintance
************************************************************************

Re:cube roots


Quote
T.Simpson wrote:

> Well, since there is no exponential function (TP only does
> squares and square roots) ... SNIP

Indeed ? I always thought exp(x:real):real was the exponential
function ;-) If it bothers you that this has the fixed base e :

 y    y*ln(x)
x  = e

(are U using a fixed font ;-)

To get back to the original problem of the cube root :

function cuberoot(x:real):real;
begin
  cuberoot:=exp((1/3)*ln(x));
end; {cuberoot}

[Untested, freshly written in the news viewer]

   __/  __/   -  Christian Froeschlin
  /    /
 /     _/     * If you eliminate the impossible, whatever remains, *
___/ _/       * however improbable, must be the BUG !              *

Re:cube roots


Quote
Timo Salmi (t...@reimari.uwasa.fi) wrote:

: In article <31561B82.6...@killroy.seanet.com>,
: Harley Bowler  <kill...@killroy.seanet.com> wrote:
: :Can some one please tell me how to calculate a cube root in Pascal? THX.

: Use the power function which you'll readily find in

:  93045 Jan 1 09:31 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
:  tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

Is it really so difficult and huge you can't... never mind.
Try this:

3rd root of a:     exp(1/3*ln a)

--
65
  Zn
30

Re:cube roots


In article <Pine.SUN.3.91.960326125036.2664D-100...@freenet2.scri.fsu.edu>
           tsimp...@freenet2.scri.fsu.edu "T.Simpson" writes:

Quote
> On Sun, 24 Mar 1996, Harley Bowler wrote:

> > Can some one please tell me how to calculate a cube root in Pascal? THX.

>         Well, since there is no exponential function (TP only does

You mean, no Exp() ?  Hmm...

Quote
> squares and square roots), you would have to create a function that takes
> a variable, squares it, and multiplies it by itself.

>         a:=sqr(x);
>         b:=a*x

> will give you a third root.

Well, I suppose it does give you a 1/3 root...

.splitbung
--
* TQ 1.0 * The 'Just So Quotes'.
"Aging is bad, but consider the alternative."
        -- anon

Re:cube roots


Quote
In article <4jbm0e$...@news.clinet.fi>, Ville Sinkko <v...@clinet.fi> wrote:
:Timo Salmi (t...@reimari.uwasa.fi) wrote:

:: Use the power function which you'll readily find in
::  93045 Jan 1 09:31 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
::  tsfaqp.zip Common Turbo Pascal Questions and Timo's answers
:
:Is it really so difficult and huge you can't... never mind.

Yes.

   All the best, Timo

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
t...@uwasa.fi http://uwasa.fi/~ts BBS 961-3170972; FIN-65101,  Finland

Re:cube roots


In article <31561B82.6...@killroy.seanet.com>,
   Harley Bowler <kill...@killroy.seanet.com> wrote:
Quote
>Can some one please tell me how to calculate a cube root in Pascal?

THX.
Try this:

function cuberoot(x: real):real;

begin
   cuberoot := x ^ 0.33333333;
end;

(raise x to the 1/3rd power)

Re:cube roots


Quote
Christian Froeschlin <froes...@cip.mathematik.uni-stuttgart.de> writes:
> To get back to the original problem of the cube root :

> function cuberoot(x:real):real;
> begin
>   cuberoot:=exp((1/3)*ln(x));
> end; {cuberoot}

> [Untested, freshly written in the news viewer]

It works a lot better if you divide by 3 instead of multiply by 1/3.
That gives *one* floating point operation rather than two. Very
important in maintaining significant figures.

cuberoot := exp(ln(x)/3);

So, that gives us the following general function for the yth root of x.

function root(x,y : real) : real;
begin
  root := exp(ln(x)/y);
end;

Leonard Erickson (aka Shadow)
 sha...@krypton.rain.com   <--preferred
leon...@qiclab.scn.rain.com        <--last resort

Re:cube roots


tsimp...@freenet2.scri.fsu.edu meinte am 26.03.96
zum Thema "Re: cube roots":

Quote
>    Well, since there is no exponential function (TP only does
> squares and square roots), you would have to create a function that takes
> a variable, squares it, and multiplies it by itself.

>    a:=sqr(x);
>    b:=a*x

> will give you a third root.

This isn t correct, because the result b = x*sqr(x) and that isn t the  
third root of x.

So long
        Rene
--------------------------------------------------------------------------
To do is to be (Socrates) To be is to do (Sartre) Do be do be do (Sinatra)
## CrossPoint v3.1 ##

Re:cube roots


Quote
R...@garfield.computer42.org (Rene Petton) wrote:
>tsimp...@freenet2.scri.fsu.edu meinte am 26.03.96
>zum Thema "Re: cube roots":

>>        Well, since there is no exponential function (TP only does
>> squares and square roots), you would have to create a function that takes
>> a variable, squares it, and multiplies it by itself.

>>        a:=sqr(x);
>>        b:=a*x

>> will give you a third root.

>This isn t correct, because the result b = x*sqr(x) and that isn t the  
>third root of x.

Excuse me if I've missed something here but the cube root of X in TP is
given by

Cuberoot:=exp(ln(x)/3);

Remember Logarithms ?

John Day

Re:cube roots


In article <Pine.SUN.3.91.960326125036.2664D-
100...@freenet2.scri.fsu.edu>, "T.Simpson" <tsimp...@freenet2.scri.fsu.e
du> writes

Quote
>On Sun, 24 Mar 1996, Harley Bowler wrote:

>> Can some one please tell me how to calculate a cube root in Pascal? THX.

>       Well, since there is no exponential function (TP only does
>squares and square roots), you would have to create a function that takes
>a variable, squares it, and multiplies it by itself.

>       a:=sqr(x);
>       b:=a*x

>will give you a third root.
>                                                               Todd

That would give the cube of x, not the cube root, try:

a:=x^(1/3)

That would give the cube root.

************************************************************************
*            When you kill a man, you're a {*word*190}er                    *
*              Kill many, and you're a conquerer                       *
*                Kill them all, YOU'RE A GOD!                          *
************************************************************************

Re:cube roots


In <lZzNmJAfBaYxE...@lunacy.demon.co.uk> Lau Gainpaulsingh <lau...@lunacy.demon.co.uk> writes:

Quote
>In article <Pine.SUN.3.91.960326125036.2664D-
>100...@freenet2.scri.fsu.edu>, "T.Simpson" <tsimp...@freenet2.scri.fsu.e
>du> writes
>>On Sun, 24 Mar 1996, Harley Bowler wrote:

>>> Can some one please tell me how to calculate a cube root in Pascal? THX.

>That would give the cube of x, not the cube root, try:
>a:=x^(1/3)
>That would give the cube root.

No, I guess it is wouldn't. To calculate x^y in pascal you must use
logarithm and exponential function:

x^y = exp(ln(x)*y)

since y root of x is x^(1/y), you get y th root of x as:
exp(ln(x)/y)), y<>0

Karel Janecek

Go to page: [1] [2]

Other Threads