Problems for Chapter 1 2022
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Problems for chapter 1
1.1 converting Numbers Between Bases
(a). convert the binary numbers to decimal numbers.
(i). (110111001.101011101)2
(ii). (1001100101.01101)2
(iii). (101.01)2
(b). convert the decimal numbers to binary. keep 10 fractional points, if needed. (i). (100.01)10
(ii). (64.625)10
(iii). (25)10
(c). write (64.625)10 into normalized scientiic notation in binary. You could use the result in the previous problem. Then determine how it would look like in a 32-bit computer, using a single-precision loating point representation.
1.2 Error propagation
perform a detailed study for the error propagation for the following computations:
(A) 从 = xg
(B) 从 = 5x + 7g
speciically, let fl(x) = x (1 + δc) and fl(g) = g(1 + δg) where fl(x) is the loating point repre- sentation of ① . Find the expression for the absolute error and the relative error in the answer fl(从).
1.3 Loss of signiicance
(a). consider the function
f (x) =“x2 + 2x + 2 - x - 1.
For what values of ① would this function be di伍cult to compute in a computer?please explain what di伍culty and why. could you ind a way to avoid this di伍culty? Explain in detail.
(b). Explain why the function
f (x) =
1
^x + 2 - ^x
can not be computed accurately in a computer when ① is large (using the above formula). Find a way around the problem.
(c). perform the following computations.
You may use 3(1) 松 0.333333, 4(3) = 0.75 and 301(100) = 0.332226.
.
(ii) compute 3(1) - 301(100) by using ive signiicant digits chopping arithmetic.
1.4 Taylor series
(a). Derive the following Taylor series for (1 + x)n (this is also known as the binomial seTies):
(1 + x)n = 1 + nx + x2 + x3 + . . . (x2 < 1)
write out its particular form when n = 2, n = 3,and n = 1/2. Then use the last form to compute ^1.ooo1 correct to 15 decimal places (rounded).
(b). use the answer in part (a) to obtain a series for (1 + ①2 )-1 .
1.5 Finite Diference, Taylor series and Local Truncation Error
Let the function f (①) be smooth. consider the inite diference approximation formula
f地 (x) 今 Dh(x) = [ —3f (x) + 4f (x + h) — f (x + 2h)] . (1)
Note that this scheme uses values of f at the three points x, x + h, x + 2h. This is a one-sided inite diference.
using Taylor series, show that the local truncation error is bounded by ch2 for some constant c, i.e.
'f地 (x) — Dh(x) ' 三 ch2 .
1.6 Matlab Exercises
The goal of this exercise is to get started with Matlab. You will go through:
. Matrices, vectors, solutions of systems of linear equations;
. simple plots;
. use of Matlab,s own help functions.
To get started, you can read the irst two chapters in“A PTactical IntToduction to Matlab”by Gockenbach. You can ind the introduction at the web-page:
http://www.math.mtu.edu/~msgocken/intro/intro.pdf
Read through the chapter “Introduction” and “simple calculations and graphs”.
How you do it:
Find a computer with Matlab installed in it. start Matlab, by either clicking on the appropriate icon(windows or Mac), or by typing in matlab (unix or linux). You should get a command window on the screen.
Go through the examples in Gockenbach,s notes.
Help!
As we will see later, Matlab has many build-in numerical functions. one of them is a function that does polynomial interpolation. But what is the name, and how to use it? You can use lookfor to ind the function, and help to get a description on how to use it.
lookfor keyword: Look after the“keyword” among Matlab functions.
There is nothing to turn in here. Just have fun and get used to Matlab!
1.7 sharpening your Matlab skills
write a function for summing all the elements in a matrix A, namely,
V = Aij .
(Hint: use the build-in function si处e to obtain the dimensions of a matrix.) You may call the function Matsum.
Then, test your function to compute the summation of all the elements of
A = l12(2).2
[ 2.5
24(.)4」.
3.4l
what to hand in: the source code for the functions, as well as the script ile for using the functions. You should also turn in the output results from Matlab.
1.8 More Matlab practice
Let a and b be two vectors of length n, i.e.,
a = [a1)a2). . . )an]) b = [b1)b2). . . )bn].
write a Matlab function that compute the value U deined as
U = [(l)bi(2) ajl(」) .
You function should begin with:
function v=myvalue(a,b)
X input: a: vector
X b: vector (same length as a)
X output: v: the computed value
Test it on the vectors a)b where
a i = i) bi = i — 5) i = 1)2). . . )10.
please turn in your Matlab function, script and the output.
1.9 A study on Loss of signiicance
In this problem we shall consider the efect of computer arithmetic in the evaluation of the
quadratic |
formula T1,2 = |
— b 干^b2 — 4ac 2a |
for the roots of p(x) = ax2 十 bx 十 c.
Below, you would ind it useful to use format short e or format numbers.
(2)
long e when displaying the
(a). write a Matlab function, call it quadroots, that takes a, b, c as input and returns the two roots as output. The function may start like this:
function [r1, r2] = quadroots(a,b,c)
X input: a, b, c: coefficients for the polynomial ax欢2+bx+c=0 . X output: r1, r2: The two roots for the polynomial .
use the formula in (2) for the computation. Run it on a few test problems to make sure that it works before you go ahead with the following problems.
(b). Test your quadroots for the following polynomials:
. 2x2 十 6x — 3
. x2 — 14x 十 49
. 3x2 — 123454321x 十 2
what do you get? why are the results pretty bad for the last polynomial? can you explain?
(c). The product of the roots of ax2 十 bx 十 c is of course c/a. use this fact to improve your program, call it smartquadroots, to see if you get better results.
Matlab has a command roots(p) which returns the roots of the polynomial with coe伍cients in p. roots is smarter than quadroots and will give accurate answers here. You can use it to check your results from smartquadroots function.
what to hand in: Hand in two Matlab function m-iles quadroots.m and smartquadroots.m, and the results you get, together with your comments.
1.10 A second study on Loss of signiicance
The exponential function has a Taylor series:
ex = 1 十 x 十 十 十 十 . . .
we approximate the exponential function with the irst 21 terms of its Taylor series, i.e.,
ex 今 1 十 x 十 2(x2) 十 3(x)!(3) 十 4(x) 十 . . . 十 2(x)0(2)!(0) = 1 十 n(x)!(n) (E)
(a). write a Matlab function MYExP(x) that computes the approximation using the formula (E). The factorial can be computed in Matlab by the function factorial.
(b). Test your function for x = 3o. compare the result with Matlab function exP(30), ind the error. use ”format short e”to display the error. Does your function work?
(c). Test your function for x = -3o. compare the result with Matlab function exP(-30), ind the error. Does your function work? can you explain your result?
(d). Based on the evidence so far, write a smart version of the function in (a), call it MYsmartExP(x) that resolves the di伍culty you encountered in (c). Test it for x = 3o and x = -3o, ind the error, and remark on your indings.
what to hand in: Hand in two Matlab functions, your script, the output, and your comments.
1.11 Number Base conversion in Matlab; (Bonus)
write a function for converting decimal to binary. You may name the function DecToBin.
(Hint: use the build-in function floor to obtain the integer part. The maximum length of the fractional binary part should be set as 16.)
Test the function by converting (12.625)10 and (21.45)10 to binary.
what to hand in: the source code for the functions, as well as the script ile for using the functions. You should also turn in the output results from Matlab.
2023-08-10