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


6CCM359A Numerical and Computational Methods

(Mock Class Test 1)


Please answer the questions by writing and executing your code on a Jupyter Notebook.

Clearly indicate the problem number above your solution, either as a Python comment or as a Markdown cell.

Save your notebook by going to File → Save as... Make sure the name of your notebook contains your student number and your full name.

Save your notebook regularly, in order not to loose your work.

Remember to submit your notebook to KEATS immediately after you finish with the test.

At the beginning of your Notebook, you can execute the following code to load the main packages:

   from numpy import *
   import matplotlib
   from matplotlib.pyplot import *


SECTION A


A 1.    [15 points] Use Python to evaluate the following expressions and print the result:

(a)

[5 points]

(b)

[10 points]


A 2.    [20 points] For each of the subquestions below use an appropriate Python method or syntax. Marks will not be awarded for typing the answers manually.

(a) Define the list (or array, as you wish) L = [1, 3, 5, 7, . . . , 35], and print the result.    [5 points]

(b) Select all elements of the list L except for the first 3 and last 2, and print the result.    [5 points]

(c) Select every second element of the list L, and print the result.    [5 points]

(d) Reverse the list L, and print the result.    [5 points]


A 3.    [10 points]

(a) Define the function

Evaluate it at x = 1.2 and print the result    [5 points]

(b) Plot the function g(x) between x = −2 and x = 2 using 400 points.    [5 points]


A 4.    [15 points]

(a) Define the following 3 × 3 matrix A and 3 × 1 vector b:

[5 points]

(b) Invert the matrix A, and print the result.    [5 points]

(c) Evaluate the vector v that solves Av = b, and print the result.    [5 points]


SECTION B


B 5.    (a) Write the function Sequence(a, b, N) which returns the list [x1, x2, . . . , xN ], with x1 = a, x2 = b and the rest given by the following recursion:

Using this function, print the list [x4, . . . , x10] that is obtained with x11, x2 = 2.    [20 points]

(b) Write the function F(n) which returns the nth element of the sequence [x1, x2, x3 . . .] with x1 = 1 and the recursion

Making use of this function, plot F(n) as a function of n for the first 30 values of n.    [20 points]


B 6.    (a) Implement the bisection method Bisection(f, a, b), where f is the func-tion whose zero we are looking for, and a, b with a < b are the two ini-tial points. The function should return the approximate value, x0, of a zero of f, and should not print anything else. Make sure x0 is such that |f(x0)| < , within a maximum of 2000 steps.    [20 points]

(b) By defining an appropriate function f(x), use Bisection to find and print the three solutions to the equation

For this purpose: (1) plot f(x) in order to identify where the zeros are, and then (2) use Bisection(f, a, b) with appropriate values of a, b to obtain and print each zero. For each zero x0, print f(x0) to check that |f(x0)| < .    [20 points]