Computer Quiz 2

This is an example problem that illustrates the type of question that will appear on the computer quiz. Note this particular example covers Newton's method, whereas only the secant method is included in the actual list of study questions.

Example Problem

Either create a new program or add the missing code and data to the program
#   Find 9 iterations of Newton's method for x0=1 and the
#   polynomial p(x)=x^5-3x^3-5x^2+15.

println("This is the example problem for Quiz 2.")

xn=[1.57142857142857, 1.65117170652226,
    1.68628082475969, 1.70211084458455,
    1.70837387112583, 1.70987638821569,
    1.7099755102779, 1.70997594666823,
    1.7099759466767 ]

function newton(x)
#   Please fix this function 
    return x
end

#   Please fix the definition of x
x=3.0

wrong=9
for i=1:9
    global wrong,x
    x=newton(x);
    println("x_$i = $x")
    if abs(x-xn[i])<1e-7
        wrong-=1
    end
end

if wrong>0
    println("Please try again.  Your answer is incorrect.")
else
    println("Congratulations!  Your answer is correct!")
end
to approximate a solution to p(x)=0 using 9 iterations of Newton's method where

p(x)=x5-3x3-5x2+15    and    x0=1.

Note that the correct answer is

x1 ≈ 1.57142857142857,  x2 ≈ 1.65117170652226,

x3 ≈ 1.68628082475969,  x4 ≈ 1.70211084458455, 

x5 ≈ 1.70837387112583,  x6 ≈ 1.70987638821569, 

x7 ≈ 1.7099755102779,  x8 ≈ 1.70997594666823, 

x9 ≈ 1.7099759466767.