You are on page 1of 2

CL244-S2 Tutorial Sheet 1 10th Aug 2022

Q1. Use zero through fourth-order taylor series expansion to predict f(2.5) for f(x)=ln x using
a base point at x=1. Compute the true percent relative error for each approximation.

Q2. Determine the relative and absolute errors when 4/3 is converted to binary format and
reconverted to decimal format. Use precision values of 4 and 6. Do this by hand.

Q3. Suppose you need to generate n+1 equally spaced points on the interval [a,b], with
spacing h=(b-a)/n.

a) Write a program implementing the following two methods and find an example that
illustrates the difference between them.

𝑥0 = 𝑎, 𝑥𝑘 = 𝑥𝑘−1 + ℎ, 𝑘 = 1, … , 𝑛

Or
𝑥𝑘 = 𝑎 + 𝑘ℎ, 𝑘 = 0, … , 𝑛

Q4. Write a program to solve the quadratic equation ax2+bx+c = 0 using the standard
−𝑏±√𝑏 2 −4𝑎𝑐 2𝑐
quadratic formula 𝑥 = or the alternative formula 𝑥 = .
2𝑎 −𝑏∓√𝑏 2 −4𝑎𝑐
You code should have the following features:
1.Your program should accept values for the coefficients a,b and c as input and produce the
two roots of the equation as output.
2. Your program should detect when the roots are not real, but need not use complex
arithmetic explicitly.
3. You should guard against unnecessary overflow, underflow and cancellation.
4. Make your program robust when given unusual input values, such as a=0 or c=0.
5. Any root that is within the range of the floating-point system should be computed
accurately, even if the other is out of range.
Test your program using the following values for the coefficients:

a b c
6 5 -4
6 * 10154 5 * 10154 -4 * 10154
0 1 1
1 -105 1
1 -4 3.999999
10-155 -10155 10155

Q5. For 100 values of x over the interval [10-9, 10-7.4], evaluate the following two expressions
that are mathematically equivalent, plot them, and based on the graphs, tell which is better
in terms of resisting the loss of significance.

i) 𝑦 = √𝑥 + 4 − √𝑥 + 3,
1
ii) 𝑦=
√𝑥+4+√𝑥+3

𝜆𝑘
Q6. Write a MATLAB code to evaluate the expression 𝑝(𝑘) = 𝑒 −𝜆 for an integer k and
𝑘!
λ=300 in a recursive way,

where p(k+1) = p(k)*/k.

300125
Use this to compute 𝑒 −300.
125!

Compare with directly evaluating above in MATLAB command line.

You might also like