首页 >
> 详细

Main Examination period 2021/22

MTH6150: Numerical Computing in C and C++

Assignment date: Monday 14/3/2022

Submission deadline: Monday 2/5/2022 at 23:59 BST

The coursework is due by Monday, 2nd May 2022 at 23:59 BST. Please submit a report

(in pdf format) containing answers to all questions, complete with written explanations and

printed tables or figures. Tables should contain a label for each column. Figures must contain

a title, axis labels and legend. Please provide a brief explanation of any original algorithm

used in the solution of the questions (if not discussed in lectures). Code comments should

be used to briefly explain your code. You must show that your program works using suitable

examples. Build and run your code with any of the free IDEs discussed in class (such as

Visual Studio, Xcode, CLion, or an online compiler), and include the code and its output

in your report. The C++ code for each question must be pasted into the pdf file of

your report, so that it can be commented on when marking. The code used to answer each

question should also be submitted separately, together with the report, in a single cpp file or

multiple cpp files. You may organise the code in different directories, one for each question.

Late submissions will be treated in accordance with current College regulations. QMPlus

automatically screens for plagiarism. Plagiarism is an assessment offence and carries

severe penalties. In the questions below, use long double if your compiler supports it. If

this is not supported, e.g. if you are using Visual Studio, you may use double.

Please read the instructions above carefully to avoid common mistakes. If in doubt, please

ask. Reports that do not contain C++ code in it (but have code included separately in .cpp

files) are subject to a 25% penalty. Reports that consist only of code and no explanation are

subject to a 40% penalty. C++ code submitted without a report is subject to a 50% penalty.

Reports not accompanied by any C++ code cannot be evaluated and will receive 0 marks.

Only material submitted through QMPlus will be accepted.

1

Coursework [100 marks]

Question 1. [20 marks] Self-consistent iteration.

Solve the transcendental equation

x = e−x

using fixed-point iteration. That is, using the initial guess x0 = 1, obtain a sequence of real

numbers

x1 = e−x0

x2 = e−x1

.

.

.

x50 = e−x49

.

.

.

which tends to the value x∞ = 0.567143 . . ., that is, a root of the function f(x) = x − e−x.

Formally, the iteration can be written as

xi+1 = e−xi for i = 0, 1, 2, . . . with x0 = 1.

The limit x∞ satisfies f(x∞) = 0.

(a) Write a for loop that performs the above iteration, starting from the initial condition

x0 = 1. Use an if and a break statement to stop the loop when the absolute value of

the difference |xi+1 − xi| between two consecutive iterations is less than a prescribed

tolerance = 10−15. Use a long double to store the values of x, and the change in

x, between iterations. Use setprecision(18) to print out the final value of x to 18

digits of accuracy. [10]

(b) In how many iterations did your loop converge? [5]

(c) What is the final error in the above transcendental equation? [Hint: use the final value of

x to compute and display the difference x − e−x.] Is the error what you expected (i.e. is

it smaller than )? [5]

2

Question 2. [20 marks] Inner products, sums and norms.

(a) Write a function named dot that takes as input two vectors A~ = {A1, ..., An} ∈ Rn and

B~ = {B1, ..., Bn} ∈ Rn (of type valarray

product

A~ ∙ B~ = Xn

i=1

AiBi (1)

as a long double number. [5]

(b) Use this function to compute the sum Pn

i=1

1

i2 for n = 106. To do so, you may define a

Euclidean n-vector A={1,1/2,1/3,...,1/1000000} as a valarray

联系我们

- QQ：99515681
- 邮箱：99515681@qq.com
- 工作时间：8:00-21:00
- 微信：codinghelp

- Fit5217辅导、Python程序语言辅导 2022-05-31
- 辅导ecs 170 Introduction To Artificial... 2022-05-31
- 辅导ecs 170 Homework Assignment 5 2022-05-31
- Fit 5003 Software Security辅导 2022-05-30
- 辅导cse 101 Data Structures And Algori... 2022-05-30
- 辅导econ7150、辅导java，Python编程 2022-05-30
- Econ7150编程辅导 讲解 S1 2022 2022-05-29
- 讲解cse 101 程序 辅导 Data Structures 2022-05-29
- 辅导fit 5003 Software Security 2022-05-29
- Stat7055 Introductory Statistics For B... 2022-05-28
- Assignment 3 Description: Computer Sy... 2022-05-28
- 辅导laboratory 程序、辅导program编程 2022-05-28
- 讲解eece 1080C Programming For Ece 2022-05-28
- Comp10002 Foundations Of Algorithms辅导... 2022-05-28
- 辅导 Swen30006、辅导java/C++编程 2022-05-28
- Comp326讲解导、辅导python，Java程序 2022-05-28
- 辅导 Dungeon Crawler C++ - Assignment ... 2022-05-27
- 辅导mast30025 Linear Statistical Model... 2022-05-27
- Prog2002辅导、辅导sql语言编程 2022-05-26
- 辅导 Info411/911 Data Mining Knowledge... 2022-05-26