(M-Files) To The Course Assistant.:) LN (4 / Log Cos) 3 2 / (6 3 1 - 0 2 / 6) 1 (1 1
(M-Files) To The Course Assistant.:) LN (4 / Log Cos) 3 2 / (6 3 1 - 0 2 / 6) 1 (1 1
2) For this question, reviewing operator precedence rules is helpful. Consider the expression given below.
y i /5 ( x 1) / y
1 e 3 i
zi
3
6 / 2 0. 1
6 /(2 3)
i
cos 2 3
2
x i y i log 2 x i / 4 ln( xi y i )
1 (1 yi ) 2 / 3
The independent variables x and y are arrays (or vectors) given as x 1 2 3 and y 3 4 5 . Note that
in Matlab, ln ( ) is given by log(x).
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.939199229068378 2.333117895415630 5.581219543558071
→ For = 2, 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 sin ( /4) to 7 significant
digits using the infinite series given below. Hence, 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 sin ( /4), the 3rd column shows the true value of sin ( /4), and the 4th and the 5th
columns indicate the corresponding values of | | and | | respectively. In your program, you can use the
built-in Matlab function factorial.
(−1)
sin( ) =
(2 + 1)!