Square Root Question

Okay, I'm attempting to make a program that finds the square root of a target number. I know how to find square roots by hand, but the problem is: How do I get that into code.
Well, I don't have trouble getting most of it into code, just the part where you take one number from the target number, use that, and then drop down the next two numbers and use those.
Can anyone help me out?
@VenomousNinja: To compute a function on computers, code is not always written in the same way a man performs the same computation. At times the methods which are easy for humans may be time-consuming or even infeasible to perform on computers. The usual way of computing most of the mathematical functions on computers is to use numerical methods.

For the square root function specifically, after finding out the greatest number less than or equal to the square root of the given number, the Newton-Raphson method can be used to find out a precise value.

Suppose that you want to find out the square root of 101.
=> x = sqrt(101)
=> x^2 = 101

There are two steps in finding out the root:

1. Use a simple for loop to find out the integer nearest to the actual answer.
Call it X0. And this X0 = 10 for our case obviously.

2. Apply the Newton-Raphson method in the following way there after to
get a precise answer:

x^2 = 101
=> x^2 - 101 = 0
=> f(x) = x^2 - 101
=> f'(x) = 2x : Derivative of (x^2 - 101) w.r.t x

The Newton Raphson method says: Xi+1 = Xi - [ f(Xi)/f'(Xi) ]

In the first step we found out that X0 = 10
Now, X1 = X0 - [ f(X0)/f'(X0) ]
=> X1 = 10 - [ -1 / 20 ]
=> X1 = 10.05

Proceed similarly iteratively till you get a satisfactorily precise answer.


Please see
http://www.shodor.org/unchem/math/newton/index.html
for a more detailed explanation of the Newton Raphson method and
http://mathworld.wolfram.com/NewtonsMethod.html for more mastery on the same.
Last edited on
I agree with msram. You use numerical methods to make your computer solve or the square root of a number. The easiest numerical method that you can use to solve the square root is Bisection. Try searching it in google. There are a lot of pages that offers tutorials about Bisection Method
Topic archived. No new replies allowed.