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

Assignment 1

March 12, 2023

Assignment 1 (15%)

Due: Friday 11:55pm, Week 4

This assignment covers content taught in weeks 1-3. You may use any of the following program- ming languages;

• Python

• MATLAB

Marks for each task will be evenly spread between;

• Code correctness

• Quality of information and presentation

• Quality of analysis

Introduction

Consider the Taylor series about a point a and the sin function.

f (x) = sin(x).

f (a) = 1 (a)(x − a)i

For the sin function, the taylor series looks like this:

sin(x) = 0  (−1)i

Unfortunately, our finite precision machines can evaluate neither the exact sin(x) function nor the infinite Taylor Series, so we must content ourselves with truncating the Taylor Series after a finite number of terms and accept a level of error.

sin(x) ≈ 0  (−1)i

Part 1 - Model Error (9 marks total)

Part 1.1 (3 marks)

Implement a function sin_taylor(x, n) which approximates sin(x) using a Taylor Series truncated after n terms.  Compare the accuracy of this function to the inbuilt sin(x) function for different

numbers of terms in the series.

Using plots and a description, explain your results.

[  ]:

Part 1.2 (1.5 marks)

The small angle theorem states that for sufficiently small values of x

sin(x) ≈ x

For example, sin(0.0001) ≈ 0.00099999983...

How small should x be for this to hold, given a tolerance of a 0.01% relative error? Using plots and a description, explain your results.

[  ]:

Part 1.3 (3 marks)

Repeat Parts 1.1 and 1.2 using the cos function. Using plots and a description, explain your results. Hint 1: you may need to derive the taylor series expansion for cos yourself.

Hint 2: The small angle theorem for the cos function is cos(θ) ≈ 1 −  for small θ

[  ]:

Part 2 - Data Error (3 marks total)

Finite Precision strikes again! π is a trancendental number, and cannot be fully stored in a finite precision machine. As a result, it is rounded after a finite number of decimal places.

Explore how the accuracy of the function f (x)  = sin(2πx) function is affected by rounding π to various degrees of precision.  Assume that your computer’s inbuilt π value is a sufficiently accuracte approximation to the true π .

Using plots and a description, explain your results.

[  ]:

Part 3 - Conditioning (4.5 marks total)

We have now explored both model and data error sources. Let’s explore things from another point of view.

Relative Forward Error is defined as the relative difference between what an ideal model with

ideal data would produce, and what our model and data produced;

RFE(x) = |f (xf) (  )|

Relative Backward Error on the other hand desribes the change in input that would result in the observed output, given an ideal model:

RBE = |  |

Now that the forward and backward error have been established, we can discuss the conditioning of a problem.

The condition number of a model is defined as the ratio between the relative forward error and

relative backward error. It describes how the function’s output changes due to changes in input. CN =

The Condition Number can also be approximated using the following formula;

CN  | )|

A function is said to be well conditioned as long as its condition number is not much greater than 1.

Calculate the conditioning of the function f (x)  =  sin(2πx) function in two ways.  Firstly, by calculating the relative forward and relative backward errors and computing their ratio. Seconly,

by using the approximation formula. Explore different regions of the domain. Let us assume the following sources of error:

• We approximate the sin function by truncating the taylor series after the first non-zero term.

• We approximate π by rounding to the nearest whole number.

Hint: You may need to find the inverse of the model used in order to find

Using plots and a description, explain your results.

[  ]: