MMU242 Hw1
MMU242 Hw1
MMU242 Hw1
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
→ 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)