Industrial Math - Alexiades
Lab 3
Roots, free software, languages
1. Use the Newton code you constructed in Lab2 to find all three roots
(one at a time!),
in double precision, of the cubic
F(x) = x3 − 1.2x2 − 8.55x + 12.15
Check, by hand, that x = −3 is an exact root.
Important: ALWAYS print residuals/errors in "%e" format to see non-rounded values!
For efficiency and accuracy, polynomials should always be
evaluated in "nested form" (Horner's Rule), like:
ax2+bx+c = c + x * (b + a*x) .
You'll probably need to plot the function to figure out good starting points.
Try at least two different starting values and discuss how convergence is
affected (count iterations).
a. Did your solver find −3 as an exact root ?
b. How do you know ? (if it was found as exact root or not)
c. If not, what could you do to increase the accuracy ? try it ! did it work ?
d. What are the other two roots ? Did your solver find them as
exact roots ?
In a text file Lab3.txt insert answers to each question,
and only the final "DONE" output line (showing root, residual, #of iterations).
and then insert code for your FCN.
2. It is useful, and often necessary(!), to be able to do the same
computation by different tools/methods.
For a little practice, search the web for root finding codes, like
fzero , brent , zeroin
in Matlab or Python or Julia or R or C.
A repository of old (.f) Fortran codes is netlib.org .
For C codes, the GNU Scientific Library is excellent.
Do the following:
a. Use whichever code you downloaded (but identify the code and from where)
to find the x = −3 root of the cubic function in Part 1.
Did it find it as exact root?
b. Do the same using Matlab or Python or Julia or R,
they have built-in root finders (fzero, fsolve, ... ).
Compare and contrast with your Newton solver (for accuracy and efficiency).
Insert answers in your Lab3.txt file and submit on Canvas.