Lecture-6 - How do Calculators Computer Square Roots? When...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science I - Martin Hardwick Lecture 1 -- 1 How do Calculators Computer Square Roots? When you enter 29 into your calculator and push the square root button, how does the calculator compute ? Consider the function x 2 – 29 = 0. it crosses the x-axis when  x  =  so, to compute the        we need to  compute exactly where the function x 2 – 29 crosses the x-axis We will use an iterative method we know the function crosses the  x -axis somewhere between 0  and 29 compute the midpoint of the interval 0 to 29 decide whether the function crosses the  x -axis before the  midpoint or after the midpoint repeat for the half of the interval in which the function crosses  the  x -axis do this until the interval is very small (0.00000001) – the  29 x x 2 – 29 -29 29 29 - 29 29
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Computer Science I - Martin Hardwick Lecture 1 -- 2 Computing Square Roots (1) #include <iostream> using namespace std; double f(double x, double num) { return (x*x - num); } Goal – find the square root of a number using the iterative Bisection Method. root is where x 2  - number = 0 We need a function that computes x 2 – number every time that we need it this is the job of function f(x) Function f(x): has two arguments, which are  type double produces a result which is  type double
Background image of page 2
Computer Science I - Martin Hardwick Lecture 1 -- 3 Computing Square Roots (2) int main () { // number to find root of double num; // end points for search double
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/04/2011 for the course CS 2400 taught by Professor Richie during the Spring '11 term at Rensselaer Polytechnic Institute.

Page1 / 10

Lecture-6 - How do Calculators Computer Square Roots? When...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online