辅导Assignment A1、讲解MATLAB程序设计、MATLAB语言辅导、讲解Mathematics

- 首页 >> Matlab编程


Individual Assignment A1


This assessment is marked out of 35 and comprises 30% of the final course mark.


Due by 1700 on Thursday week 8.


Academic misconduct


The assessment is primarily summative in nature. You are expected to be aware of and abide by University policies on academic misconduct.

School of Mathematics academic misconduct advice and policies

Academic Services academic misconduct information


This is an individual assignment - do not copy the work of another student.


If you use any resources (e.g. textbooks or websites) then include appropriate references in your solutions. Course materials do not need to be referenced.


Markdown


In workshops you have edited Jupyter Notebook "code" cells. Cells can also contain formatted text in "markdown" cells. Some questions ask for further discussion and explanation, which should be provided in appropriate markdown cells. You may wish to use formatting features of markdown cells, although this is optional.

Jupyter Notebook: Markdown cells


You can edit markdown cells (e.g the cell initially containing "Discussion for question 1.1" in question 1) by double clicking on them, and render the markdown by selecting the cell and pressing Shift+Return.


Code commentary


Your code should be extensively commented, with the functionality of each line of code explained with a comment. This is to test your understanding of the code you have written. Up to half of the marks associated with the coding part of a question may be deducted for a missing, incomplete, or inaccurate code commentary.


The following provides an example of the expected level of commenting.


In [ ]:

def is_prime(n):

   """

   Return whether an input positive integer is prime.

   """

   

   if n == 1:        # If n is 1 ...

       return False  # ... then n is not prime

   

   for i in range(2, n):  # Test integers i from 2 to n - 1 inclusive

       if n % i == 0:     # If n is divisible by i ...

           return False   # ... then n is not prime

   # If n is not divisible by any integers from 2 to n - 1 inclusive then n is

   # prime

   return True

Output and figures


Your code must generate and display all relevant output when run, and all figure formatting must be performed programmatically and not via the interactive plotting interface.


Rerun your code cells after editing your code, to make sure that the output is updated.


Saving your work


When you edit the notebook, before closing the window/tab make sure to select "File"->"Save and Checkpoint". If using Noteable make sure you also download and keep a copy of the edited file, using "File"->"Download as"->"Notebook".


On lab computers make sure you save edited notebook files in an appropriate location, as otherwise they may be lost when you logout.

Information Services: Saving your files


Question 1: Numerical linear algebra


This question is based on question 1.8 in chapter 1 of

Numerical Computing with MATLAB, C. Moler, 2004


Consider the matrix

$$Q = \left( \begin{array}{cc} 1 & 1 \\ 1 & 0 \end{array} \right).$$

1.1 Investigate what you obtain when $Q$ is multiplied by itself $n$ times. Can you identify any other properties of the matrix Q?


Your code should display output that is easy to interpret and understand. Summarise and explain your results in a discussion of no more than $250$ words.


[6 marks]


In [ ]:

# Code for question 1.1


Discussion for question 1.1

Question 2: Interpolation and fitting


The following data are taken from T. A. Boden, G. Marland, R. J. Andres, "Global, regional, and national fossil-fuel CO? emissions". Carbon Dioxide Information Analysis Center, Oak Ridge National Laboratory, U.S. Department of Energy, Oak Ridge, Tennessee, U.S.A., 2017, doi:10.3334/CDIAC/00001_V2017.

?CDIAC: Global fossil fuel CO? emissions


These provide estimates of global CO? emissions from 2004 to 2014 inclusive, in millions of tons of carbon.



Year


Emissions



2004 7743

2005 8042

2006 8336

2007 8503

2008 8776

2009 8697

2010 9128

2011 9503

2012 9673

2013 9773

2014 9855


2.1 Plot

1.A scatter plot of the original data.

2.An interpolating polynomial fitting through the data.

3.A degree five least squares fitting polynomial, fitting the data in a least squares sense as described in the week 6 lecture and workshops.

4.A cubic spline through the data generated using scipy.interpolate.CubicSpline provided with SciPy.

5.A cubic spline through the data generated using scipy.interpolate.PchipInterpolator provided with SciPy.


You should choose how to present the plots so that the data presentation is clear and easy to understand.


[7 marks]

In [ ]:

# Code for question 2.1


2.2 Which do you think provides a more useful fit to the data? Justify your answer using no more than $350$ words.


[5 marks]

Discussion for question 2.2


Question 3: Gaussian elimination


3.1 Write a function named eliminate_super_diagonal which accepts two input arguments

1.an $N \times N$ real (floating point) matrix $A$ for which $A_{j + 1,j + 1} \ne 0$, with $N \ge 1$,

2.an index $j$, where $j \in \left\{ 0, \ldots, N - 1 \right\}$,


and applies elementary row operations to eliminate all entries above the main diagonal in the $\left( j + 1 \right)$th column of $A$ (where here the rows and columns of $A$ are referred to indexing from one).


That is, on returning from the function, all elements in $A$ from row $\left( j + 1 \right)$ to row $N$ should be left unchanged, while elementary row operations are applied so that, on returning from the function, $A_{k,j + 1} = 0$ for all $k < j + 1$.


Hint: Functions can modify arrays "in-place", changing the values of elements and without first creating a copy, e.g.

import numpy as np


def increment_element(A, i, j):

  A[i, j] += 1.0


R = np.ones([10, 10])

# R[5, 5] equals one

increment_element(R, 5, 5)

# R[5, 5] now equals two


[4 marks]

In [ ]:

# Code for question 3.1

3.2 Write a function named gaussian_elimination which accepts an input square matrix $A$, of size $N\times N$, and applies elementary row operations to $A$ to obtain a lower triangular matrix. You should decide how to handle division-by-zero problems, and explain your decision.


You may wish to consider how your gaussian_elimination function handles the matrix

$$A = \left( \begin{array}{ccc} 1 & 1 & 1 \\ 3 & 1 & 0 \\ 2 & 1 & 0 \end{array} \right).$$

[7 marks]


In [ ]:


# Code for question 3.2

Discussion for question 3.2

3.3 How does the cost of gaussian_elimination increase as $N$ increases? Justify your answer, including numerical tests, and a discussion of no more than $250$ words.


[6 marks]


In [ ]:

# Code for question 3.3


Discussion for question 3.3




站长地图