MMU242 Hw1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

MMÜ 242 - NUMERICAL ANALYSIS - SPRING 2022 - HOMEWORK 1

Due: 7 March 2022, Monday


*Display your results in double-precision.
*For this homework only, you can omit the Introduction and Discussion sections in your report.
*E-mail your homework reports and Matlab programs (m-files) to the course assistant.

1) Type the following commands in the same order as given below. Explain very shortly the results by
describing the functions of the given commands and operators. The commas separate the commands only.
C=[4 6 6; 2 1 8; 4 4 3], C^2, disp(C*C), C.^2, C/2, C./2, 1/C, 1./C,
C(:, [3 1]), C(end,:), C(1:3, [2 3])=9, C([1 3], :)=[ ]
B=[1 3 5;2 4 6;1 7 9], D=[4 6 6; 2 1 8; 4 4 3], B*D, B.*D, B./D, 2.^B
a=[2 4 6], d=[1 3 5]', 5-a, d^3, d.^3, a+d, a.*d, (a.*d')', a./d, a'./d, F=[B D; a d']

2) For this question, reviewing operator precedence rules is helpful. Consider the expression given below.
/ 8
| | 2 × 5 + 6 × 2 /3 × 4 ∙ ln ( )
log ( ) ∙ 10 ∙
= +
4! × 1.5 × 2.8/3.16 ( . ) ∙ ( )∙ |cos( − )| ∙ 0.25

The independent variables x and y are arrays given as = [4 2 1 3] and = [2 1 0.5 1].
Compute the values of z using the following methods described in parts (a), (b), (c) and (d).
a) Apply for loop.
b) Define z in a single line using array multiplication and division operations of Matlab.
c) Use the inline command or use function handles with the operator @.
d) Write a function m-file which accepts x and y as input arguments and returns z as the output argument.
Note: You must find the same answer for parts (a), (b), (c) and (d). The correct answer is:
z= 1.0e+002 *
1.240352767733293 0.157855260277145 0.331266383709557 0.004812121020856

3) Consider the function ( ) = .


→ For ∈ [−3, 3], plot ( ) and the Taylor polynomials ( ), ( ), ( ), ( ) of about the base
point = = −1. Plot these five functions in the same figure. Use an increment (i.e. step size) of 0.01 to
plot these functions. Draw ( ) using black solid line; draw ( ) using red solid line; draw ( ) using
green dash-dot line; draw ( ) using blue dashed line; draw ( ) using magenta dotted line. (Typing the
keyword “linespec” in Matlab help would be useful to you). The limits for the axes of the figure must be
= −4, = 4, = −5, = 25 . Label the x and y axes, and put the title Homework 1 -
Question 3 on the figure.

→ For = 0, approximate ( ) using Taylor polynomials of order 0 to 3. Then, find the corresponding
true percent relative error for each case.

→ In your figure, mark the base point ( , ( )) with a red circle and mark the true-value point ( , )
with a black circle.

4) Write a program to determine the number of terms required to approximate arctan(-0.4) to 8 significant
digits using the infinite series given below. The program should terminate automatically when the criterion
= (0.5 × 10 )% is met (i.e. when | | < ). Display your results in tabulated form in which the 1st
column shows the number of terms used in the series, the 2nd column lists the corresponding approximation
for arctan(-0.4), the 3rd column shows the true value of arctan(-0.4), and the 4th and the 5th columns indicate
the corresponding values of | | and | | respectively. Remember that | | is the approximate percent
absolute relative error and | | is the true percent absolute relative error.

(−1)
arctan ( ) = | |<1
(2 + 1)

You might also like