Question solution for SICP ---- exercise in section 1.1, question solution for sicp ---- 1.1

Source: Internet
Author: User

Question solution for SICP ---- exercise in section 1.1, question solution for sicp ---- 1.1

Exercises in section 1.1 include exercises 1.1 to 1.8

Exercise 1.1 -- 1.6 has been given in the first section of constructor abstraction.

The following is a question for exercise 1.7 and exercise 1.8.

Practice 1.7

First, observe the program problems in the textbook.

It can be found that sqrt given in books cannot calculate the correct answer for a particularly small number, such as 0.00009. For a particularly large number, because the decimal precision is not enough to indicate the difference between two large numbers, sqrt will fall into an endless loop and cannot produce results.

To avoid this error, we follow the practice instructions for good-enough? Modify: the program does not detect the difference between the square of the guess value guess and x, but the ratio between the new and old guesses. When the ratio changes very small, the program stops improve.

New good-enough? Definition:

(Define (good-enough? Old-guess new-guess x); old-guess * newguess/x-1 (<(abs (-(/(* old-guess new-guess) x) 1 ))

The result is as follows:

Practice 1.8

Simply modify the Newton method to obtain the square root.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.