Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

2023T1 MATH2089 – Numerical Methods Tutorial Problems (MATLAB*)

Week 1

*Python version for this tutorial is available as a Jupyter notebook from the course Moodle page. Topic: §1 Numerical Computing

1.  [M] You will need to become familiar with Matlab, downloading example M-iles from the course Moodle page and editing and creating M-iles.

(a) Download the Matlab M-ile explot.m from the MATH2089 Numerical Methods com- ponent course Moodle page.  Try left-clicking on the name of the ile, and choosing the option to save the ile (make sure you save it in an appropriate folder).  Alternatively, right-click on the ile name and choose Save Target As ... or Save Link As ....

(b) Start Matlab and run this M-ile by typing explot in the Matlab command window. Note that the ile explot.m must be in Matlab’s current working directory.

(c) Use the Matlab editor to open the ile explot.m. Run this M-ile by clicking on the Run button.

(d) The next few questions can be done interactively by typing the commands directly into the Matlab command window.  However it is better to create M-iles containing these commands using the Matlab editor.  You may wish to have a separate M-ile for each question. Or you may have one ile for multiple questions in the same tutorial, but separate commands from diferent questions into blocks with %% and run a single block at a time by clicking on the Run Section button.

(e) Download the template ile week1.m from Moodle. We will use it throughout this tutorial. (There are template iles on Moodle for future tutorials.)

2.  [M] Matlab has built-in values for some common mathematical constants, such as pi for T .

(a) What do you get if you type pi in the Matlab command window?

(b) What do you get if you enter format long and then pi?

(c) What is the value of T rounded to 8 signiicant igures?     (Do it by hand)

(d) Deine the variable p = 3.1416. What is the absolute error and the relative error in using p as an approximation to T .

(e) Calculate x = 2  1030 , y = sin(x).  (The correct value is y  0.1795 using Maple and extended precision.)

(f) Plot the values of yk  = sin(T10k ) for k = 1, . . . , 100. Compare with the true value.

3.  [M] Floating point number systems are only inite approximations to the real number system, based on a inite binary representation of numbers. Thus powers of 2 are represented exactly, but powers of 10, for example 0.1, may not have a inite binary representation so must be approximated by the closest loating point number.

A logical true is represented by 1 (or any non-zero number in some systems) and a logical false by 0.

Try the following operations in Matlab

(a) 0.75*0.2 - 0.15

(b) floor(6/1), floor(0.6/0.1)  (floor(x) is the largest integer  x.)

(c) h = 1e-14, 100+h-100

(d) h = 1e-15, 100+h-100   (e) eps, realmax, realmin  (f) eps, 1+eps >1, 1+eps/2>1

4.  [M] IEEE loating point arithmetic has a special representation for NaN, (standing for Not a Number) which is used for quantities that are not mathematically deined.  Some systems (for example Matlab) also have special representations Inf for +∞ and -Inf for -∞ .  If an operation produces one of these quantities then they can propagate throughout subsequent calculations.

Try the following operations in Matlab

(a)  1/0,        -1/0,        log(0),        log(-1)

(b) 0/0,        Inf - Inf.        0*Inf,        0*NaN

5.  [M] Use the Matlab online help system,

• help command or

•  Matlab documentation using Help menu item or helpdesk command,

to ind out information on the commands used in the previous exercises, including

(a) eps, realmax, realmin

(b) floor, ceil

(c) log, log10, log2

(d) ops

6.  [M] The Matlab function exp gives the exponential function.

(a) Find the largest integer value of t > 0 such that on your computer system et  is a inite number.

(b) Calculate the value of e t  for t = 700, 710, 720, . . . , 800.