Results 1 to 4 of 4

Thread: The n'th (not square) root of a number?

  1. #1

    Thread Starter
    New Member Martin's Avatar
    Join Date
    Apr 1999
    Location
    Alleroed, Denmark
    Posts
    10

    Question

    I know the Sqr function, but how do i make a function which retrieves another root than the square root?

    I tried searching the help files, but it doesn't seem that there's a built-in function to do the trick.

    Anyone knows the algorithm?
    Martin

  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    Code:
        Public Function nSqr(ByVal number as Double, _
                             ByVal n as Double) as Double
            nSqr = number ^ (1 / n)
        End Function
    'Usage:
        Label1.Caption = nSqr(81, 4) 'returns 3
        Label1.Caption = nSqr(27, 3) 'returns 3
    Bit of rough code, but it should do the trick
    Hope it helps

    [Edited by r0ach on 05-19-2000 at 02:13 PM]

    r0ach™
    Don't forget to rate the post

  3. #3
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Sedgefield
    Posts
    337
    Or...

    Code:
    Public Function NthRoot(num As Double, RootOrdinal As Double) As Double
        
        NthRoot = Exp(Log(num) / RootOrdinal)
        
    End Function


    Dan

  4. #4

    Thread Starter
    New Member Martin's Avatar
    Join Date
    Apr 1999
    Location
    Alleroed, Denmark
    Posts
    10

    Thumbs up Thanks

    Thanks for the quick answer, guys!

    For the moment i don't need the function, but i've saved it in a module for future reference. BTW I didn't know Exp(Log(num) / RootOrdinal), but I should have remembered the number ^ (1 / n). (I just learned some of it in highschool.)

    Cheers
    Martin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width