none
has anyone got a program for finding the square root of a number? RRS feed

  • Question

  • I know it should work, but I can't figure out how to set it up. I am sure it has already been done and if I could look at it I would appreciate it. Thanks
    Thursday, November 12, 2015 5:24 PM

Answers

  • Yup! Use Math.SquareRoot

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, November 12, 2015 6:06 PM
    Answerer
  • :-)

    There should have been something, try a forum search for newton method or 'newton' or similar. I would'nt search for 'method'.

    .. Or as an alternative to Zock's solution, use Math.Power(num, 1/2)


    You can try this as a first base for a SQR iteration, you can move forward with (maybe enclose in a loop):

    num = TextWindow.ReadNumber()
    diff = 0.00001  ' the lower, the closer to the result
    
    guess = 2
    root = 0  ' better num/2, brings you closer to the result
    tmp = guess
    
    While Math.Abs(tmp - root) > diff
      root = tmp
      tmp = root - (root*root - num) / (guess * root)
    EndWhile
    TextWindow.WriteLine(root)
    Code from math.sqrt vs. Newton-Raphson Method for finding roots in c#




    Thursday, November 12, 2015 6:22 PM
    Answerer

All replies

  • Yup! Use Math.SquareRoot

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, November 12, 2015 6:06 PM
    Answerer
  • :-)

    There should have been something, try a forum search for newton method or 'newton' or similar. I would'nt search for 'method'.

    .. Or as an alternative to Zock's solution, use Math.Power(num, 1/2)


    You can try this as a first base for a SQR iteration, you can move forward with (maybe enclose in a loop):

    num = TextWindow.ReadNumber()
    diff = 0.00001  ' the lower, the closer to the result
    
    guess = 2
    root = 0  ' better num/2, brings you closer to the result
    tmp = guess
    
    While Math.Abs(tmp - root) > diff
      root = tmp
      tmp = root - (root*root - num) / (guess * root)
    EndWhile
    TextWindow.WriteLine(root)
    Code from math.sqrt vs. Newton-Raphson Method for finding roots in c#




    Thursday, November 12, 2015 6:22 PM
    Answerer