Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / For MATLAB codes and their outputs (plots etc

For MATLAB codes and their outputs (plots etc

Math

For MATLAB codes and their outputs (plots etc.) you should follow the “pub-
lish” procedure explained in Matlab Tutorial 2.

e All MATLAB codes and relevant output must be included in your PDF output
in order to gain full credit.

e Make use of semi-colons (;) to suppress unnecessary Matlab output. Marks may
be deducted if unnecessary output has led to an excessive number of additional
pages in your assignment submission.

1. [5 marks] Archimedes’ sequence
m1 =2, Yao = 24/2 (1 ~/1— (Yn/2")?), n=1,2,... (1)
converges to 7, lim yp, = 7.
n—-Oo
(a) [1 mark] Write a program in MATLAB to compute y, for n = 1,2,...,40. Create a vector
y= [yi ye ---Yyao| and print out the vector y.
(b) [1 mark] Plot the vector y against [1 2 --- 40], also plot the constant function pi.
(Hint: To plot a constant C on N points you can create the vector z = C' * ones(1, N) and
plot it. To include several plots in the same axes, make sure you use “hold on”.)
(c) [1 mark] Explain why the approximations y,, start getting worse around n = 25, as opposed
e.g. to n around 10. Which operation can be seen to specifically become problematic around
n = 25?
(d) [1 marks] Show that the recursive formula (1) is mathematically equivalent to
2
Zz, = 2, pt) = nH 12... (2)
4/2 (a +/1—- (2n/2")?)
i.e. show that y, = 2, for all n.
(e) [0.5 marks] Write a program in MATLAB to compute z, for n = 1,2,...,40. Create a vector
z= |Z, z2 ---+2Z49] and print out the vector z.
(f) [0.5 marks] Plot the vector z against [1 2 --- 40], also plot the constant function pi.
2. [5 marks] In MA21003 (Discrete Mathematics) you have seen Newton’s method for the solution
of a nonlinear equation
f(z) =0.
In particular, Newton’s method reads as
f (Zn)
= - WT TY — QO, 1, eee 3
Pret = tn Fig)” °
where the initial guess x9 is given and should be “close enough” to the solution of f(x) = 0 that
we are interested to approximate.

 Implement Newton’s method in order to find the unique root of
2 —2r—-1=0, x € (0, 2]
using as initial guess 79 = 2. Use a loop to create 2,41 in terms of z,, and also implement the
termination criterion
ltng41 —2n}< 107° AND — [22,,-—2n41—-1]< 107% (4)
in the same code. Plot all the generated x, against n. Print the value of the last iteration,
Z,, and the number of iterations required to satisfy the termination criteria.
(b) [1 mark] For practical reasons, when using Newton’s method we will need to restrict the total
number of iterations. If after a very large number of iterations reasonable termination criteria
(as the one above) have not be met, usually this is a sign of non-convergence, i.e. continuing
further would not improve things.
Add the termination criterion
n < 1000
to your code. For which of the initial guesses
1. L0 = 0.641
ll. Lo = 0.64
lli. Lo = 0.639
lv. Zo = 0.638
does your code converge numerically (in the sense of satisfying the criteria of equation (4)) in no
more than 1000 repetitions? (For this part, simply state the answer, there is no need to “publish”
any codes again.)

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE