Assignment 4 Numerical Computing BMAT1 2023 24

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Numerical Computing - B. Math.

I
Assignment 4 — 2nd Semester 2023-2024

Due date: 25 February, 2024


Note: Total number of points is 20. Two questions out of the six below will be graded
(the choice is upto me but uniform for all students). There are 4 points for completion.
Plagiarism is prohibited. But after sustained effort, if you cannot find a solution, you may
discuss with others and write the solution in your own words only after you have understood
it.

1. (8 points) (i) Write a Bisection(a) function in Octave which takes in a real number

a and finds an approximation to 3 a to within 10−4 using the bisection algorithm.
(ii) Write a function Dist(a, b) in Octave which uses Newton’s method to compute
the value of x0 (to within 10−4 ) which is the point on the graph of the parabola
y = x2 that is closest to (a, b) ∈ R2 . (If the answer is not unique, which answer
does your code prefer?) Compute the value Dist(1,0).

2. (8 points) In the bisection method, let M denote the length of the interval [a0 , b0 ]. Let
(x0 , x1 , x2 , . . . , ) represent the successive midpoints generated by the bisection method.

(i) Show that


M
|xi+1 − xi | = .
2i+2
Also show that the number of iterations, I, required to guarantee an approximation
to a root to an accuracy ε is given by
log(ε/M )
I > −2 − .
log 2

(ii) The bisection method can be used whenever f (a0 )f (b0 ) < 0. If f (x) has more
than one zero in ther interval, which zero does the bisection algorithm (discussed
in class) usually locate?

3. (8 points) Implement a function newton(f,x0 ) which finds the roots of a function f


when initialized at x0 . (You may refer to the NMM Toolbox shared on Moodle for
sample code.) Find the roots of the functions below, with x-tolerance and f -tolerance
to be within 5 × 10−16 . What is the number of iterations required for convergence and
what is the value of the root?
1
(i) x − x 3 − 2 = 0 with initial guess x0 = 3
(ii) e2x − ex − 2 = 0 with initial guess x0 = 0.5

Statistics and Mathematics Unit, Indian Statistical Institute Page 1 of 2


Soumyashant Nayak: soumyashant@isibang.ac.in
Numerical Computing - B. Math. I: Sheet 4— 2nd Semester 2023-2024

4. (8 points) Implement a function secant(f,x0 ) which finds the roots of a function f


when initialized at x0 . (You may refer to the NMM Toolbox shared on Moodle for
sample code.) Find the roots of the functions below, with x-tolerance and f -tolerance
to be within 5 × 10−16 . What is the number of iterations required for convergence and
what is the value of the root?

(i) x3 − 2x − 1 = 0 with initial guess x0 = 1


(ii) 4 sin x − ex = 0 with initial guess x0 = 0.5

5. (8 points) For each of the following equations, determine an iteration function (and an
interval I) so that the conditions of the contraction mapping fixed-point theorem are
satisfied (assume that it is desired to find the smallest positive root):

(i) x3 − x − 1 = 0
(ii) x − tan x = 0
(iii) e−x − cos x = 0.

Write a function fixPt(f) which implements the fixed point iteration algorithm for a
function f . Use it to find the smallest positive root of the above three equations.

6. (8 points) (i) The equation ex − 4x2 = 0 has a root between x = 4 and x = 5. Show
that we cannot find this root using fixed point iteration with the “natural” iteration
x
function x = 21 e 2 . Find an iteration function which will actually find the root.
(ii) The equation ex − 4x2 = 0 also has a root between x = 0 and x = 1. Show that
x
the iteration function x = 21 e 2 will converge to the root if the initial value x0 is
chosen to be in the interval [0, 1].

Statistics and Mathematics Unit, Indian Statistical Institute Page 2 of 2


Soumyashant Nayak: soumyashant@isibang.ac.in

You might also like