Lab 3

Write a code

The code should accept inputs:

(neatly, in columns, use format: %d %f %14.5e %14.5e ), and upon convergence it should print out:

value of the root, the residual, the error and how many iterations it took.

The (formula for the) function F(x) should be coded in a

You may set maxIT=100; in the code.

Of course, you must debug the code ( on a problem with known solution, e.g. F(x)=1.3−x on [1,2], TOL=1.e-7 and 1.e-14 ).

Let's try to find the zero(s) of the function

1. First, of course, we ask: Are there any? Plot it to get an idea what the curve y=F(x) looks like.

This is easiest to do in gnuplot: gnuplot>

It crosses the x-axis and looks very flat on it, ...many roots ? (

Notice the very big range on the y-axis which makes small variations invisible, so we can't really see much at this scale.

2. To resolve it better, plot it on a smaller interval, say, [−2,2]:

gnuplot>

It looks much better, doesn't it? It crosses the axis three times, so there are three real roots.

Write down rough estimates of the three roots (at least 2 decimals).

3. Now let's focus on the largest root to resolve it better: Magnify the scale (zoom-in) around the largest root:

gnuplot>

Now it's better resolved, and can zoom-in further: gnuplot> set xrange [1.6 : 1.8] and: replot

Repeat zooming in until you can estimate the root to at least

This is the

Can you "guess" the

1. Now that we know our function has a (single) root in [1, 2], and it has opposite signs at x=1 and x=2,

we can use the Bisection Method to locate the root as accurately as we want,

provided F(x) is continuous on [1, 2]. Is it ? Justify your answer,

2. Now use your bisection code on the cubic, with the following inputs:

(a)

(b)

(c)

(d)

For each run, record the values found for root and F, and how many bisections it took.

Answer the questions:

Q2: What is the effect of changing the tolerance ?

Q3: What is the effect of changing the interval [a, b] ?

Q4: Can you explain the failure in (d) ?

Then insert your

Then submit it on Canvas by due date.