SICP exercise 1.40

From Drewiki

Jump to: navigation, search

Problem

Define a procedure cubic that can be used together with the newtons-method procedure from the text in expressions of the form (newtons-method (cubic a b c) 1) to approximate zeros of the cubic x3 + ax2 + bx + c.

Solution

Here's cubic:

 

And here's newtons-method and friends from the text:

 

Tests performed using Chicken Scheme 3.1 on a MacBook Pro running Mac OS X 10.5.

 

Output:

-0.99999999999978
 

Output:

2.65319902917972e-05
 

Output:

1.0
 

Output:

-1.99999999998065
Personal tools