首页 > > 详细

MA1MSP留学生讲解、Statistical Programming辅导、讲解MATLAB编程语言、辅导MATLAB 解析C/C++编程|讲解

MA1MSP: Mathematical and Statistical Programming
Assignment 2
This assignment counts to 35% of the total marks of this module. Full marks of this
assignment can be gained from complete answers to ALL questions and emailing me the
.m file at john.evans.18@nuist.edu.cn before 12pm (noon) on 10th April, 2019 (Wednesday).
Note: For the EACH of the following FOUR questions
Put your MATLAB code into an individual script with the file name of ‘MSP Asgn2 Qx StudentID.m’
where ’x’ should be the question number (namely one out of 1, 2, 3, 4) and ’StudentID’ should be
your Student ID number.
At the beginning of each script, add a comment line to state ‘This is the script for Q.x of
Assignment 2’ where ‘x’ is the question number.
All four scripts should be uploaded to the same email as one submission. Be sure to put your
student number in the Subject line.
1. Consider a function
f(z) = z + (z/2)2
where z = x + iy is a complex number with x, y ∈ R.
Take the magnitude of z with r = 6 and its argument varying in the range of θ ∈ [0, 2π]. Write
a MATLAB code to do the following:
(a) plot the function f(z) as a smooth curve of solid line with linewidth 3 and blue colour in
the complex (Re(f) Im(f)) plane.
(Hint: you may use the Euler’s formula z = reiθ for conveniently calculating the real and
imaginary parts of the function.)
[4 marks]
(b) add proper legend, x-label, y-label, title, and set the aspect ratio of the axes so that equal
tick mark increments on the x- and y-axis are equal in size. To find the right command
you can type ’help axis’ in the command window.
[1 marks]
2. Consider a series of numbers generated by the recurrence relation
an = an?1 + n
with the initial term a0 = 4.
(a) Given f(1) = a0, use a for loop to generate the first N = 30 + X terms of this series
which should be stored in an array f(i), i = 1, 2, . . . , N + 1. Here X is the last digit of
your student ID. Output this array on the screen (Command Window);
[4 marks]
1(b) Write another for loop to calculate
using the array f(i) (i = 1, . . . , N + 1) generated in Part (a). Output the values of S and
on the screen (Command Window).
[2 mark]
3. Consider using the formula
to approximate the function
ye = arcsin(x).
(a) Plot these two functions over the interval of x ∈ [0, 1] in the same figure, where the
approximate curve is of solid line, square markers and magenta colour, and the exact
curve is a dot-dashed line with square markers and black colour.
[4 marks]
(b) Plot the error incurred by the approximation, which is defined as the absolute difference
between the exact and the approximate values, over the same interval and in the same
figure as in (a). This error curve should be of dashed line, triangle (down) markers and
cyan colour.
[2 mark]
(c) The figure should also have the following features:
legends for the three curves ’Approximate’, ’Exact’ and ’Error’;
x-axis labelled as ’x values’ and y-axis labelled as ‘y(x)’;
title of ’Approximation of the Inverse Sine Function’.
[1 mark]
4. The function sin(x) can be approximated by the truncated Taylor series
(a) To illustrate how well the series approximates the sin(x) function, use a for loop to
generate a set of m plots, which correspond to the functions of y(x) = Pn
i=0(1)i x2i+1(2i+1)!
where n = 1, 2, . . . , m with m = 5 if the last digit of your student ID is odd or m = 6 if
the last digit of your student ID is even, respectively, over the interval of x ∈ [0, π] in the
same figure. All m curves should be of dotted blue lines. In addition, plot the function
y(x) = sin(x) as a solid red curve over the same interval and in the same figure.
[5 marks]
2(b) To understand how the approximate value converges to the exact value with the increase
of number of terms in the summation, first set the value of x to a constant x = π/4. Then
use a for loop to generate an array f(i), i = 1, 2, . . . , 10, where the i-th element is given
[4 marks]
Plot the array f(i) as a dashed blue curve with x-mark and the function y(i) = sin(π/4)
as a solid black line over the interval i ∈ [0, 10] in a separate figure to part (a).
[2 marks]
(c) For the same constant value of the argument x = π/4, use a while loop to carry out the
summation in Equation (1) until the absolute value of the difference between the summed
value and the exact value of sin(π/4) is no larger than = 1010. Output the final result
of the summed value and the total number of iterations [i. e., n in Equation (1)] used for
the summation on screen (Command Window).
[6 marks]
3

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!