## Part 1

1. ½Ð¦b MATLAB ª½±µ¿é¤J¤U¦C±¼Æ¡A¬Ý¥¦­Ìªº­È¬O¦h¤Ö¡G
1. i
2. j
3. eps
4. inf
5. nan
6. pi
7. realmax
8. realmin
2. ½Ð¨Ï¥Î lookfor «ü¥O¡A§ä¥X¨ã¦³¤U¦C¥\¯àªº MATLAB «ü¥O¡C¡]¨C¤@¶µ¥u»Ý§ä¥X¤@­Ó ¬ÛÃö«×³Ì°ªªº MATLAB «ü¥O¡C¡^
2. §ïÅÜ¯x°}ªº¤j¤p¡]¨Ò¦p±N 4¡Ñ6 ªº¯x°}§ï¦¨ 12¡Ñ2¡^
3. ±N¯x°}¥ª¥kÂ½Âà¡]Left-right flip¡^
4. ±N¯x°}¤W¤UÂ½Âà¡]Up-down flip¡^
5. §ä¥X¯x°}¨C¤@ª½¦æªº³Ì¤j­È
6. ¹ï¯x°}ªº¨C¤@ª½¦æ¶i¦æ±Æ§Ç
7. ¯x°}ªº±ÛÂà¡]Rotate¡^
8. ¤Ï¯x°}¡]Inverse matrix¡^ªº­pºâ
9. ¨D¯x°}ªº rank
10. ­pºâ¯x°}ªº reduced row echelon form
11. ­pºâ¯x°}ªº null space
13. ­pºâ¯x°}ªº QR ¤À¸Ñ¡]QR Decomposition¡^
14. ­pºâ¯x°}ªº LU ¤À¸Ñ¡]LU Decomposition¡^
16. ¹ï¦V¶q¶i¦æ§Ö³t³Å¥ß¸­Âà´«¡]Fast Fourier Transform¡^
17. ª½¨¤®y¼ÐÂà¦¨·¥®y¼Ð
18. ·¥®y¼ÐÂà¦¨ª½¨¤®y¼Ð
3. (*)When does n! explodes: Write a MATLAB script to find the minimal value of n such that n!>realmax. What is the value of n? What is the value of (n-1)! ?
4. ¼g¤@­Ó MATLAB ¤pµ{¦¡ findN01.m¡A¨D¥X³Ì¤pªº n ­È¡A¨Ï±o n! > realmax¡C½Ð°Ý n ªº­È¬O¦h¤Ö¡H¦¹®É (n-1)! ªº­È¤S¬O¦h¤Ö¡H
5. MATLAB ªº sqrt «ü¥O¥i¹ï¥ô¤@¼Æ­È¶i¦æ¶}¥­¤èªº¹Bºâ¡C¥Î¦¹«ü¥O¨D¥X¤U¦C¦U¼Æªº¥­¤è®Ú¡A¨ÃÅçºâ¤§¡G
1. p
2. 2*i
3. -5+12*i
¨ä¤¤ i ¬O³æ¦ìµê¼Æ¡C
6. (*)Basic function for both scalar and vector inputs: Write a MATLAB function to evaluate the following expression:
0.5*exp(x/3)-x*x*sin(x)
where x is the input and y is the output of the function. You function should be able to handle both the situations when x is a scalar or a vector. Please use the following code segment to plot the expression: x=0:0.1:10; plot(x, myFun01(x));
7. ¼g¤@­Ó MATLAB ¨ç¼Æ myFun01.m ¨Ó­pºâ¤U¦C¤èµ{¦¡¡G
y = 0.5*exp(x/3)-x*x*sin(x)
¨ä¤¤ x ¬O¨ç¼Æªº¿é¤J¡Ay ¬O¨ç¼Æªº¿é¥X¡C§Aªº¨ç¼Æ¥²¶·¯à°÷³B²z·í x ¬O¯Â¶q©Î¬O¦V¶qªº¨âºØ±¡ªp¡C¦¹¥~¡A½Ð§Q¥Î¤U­z¨â¦Cµ{¦¡½X¨Óµe¥X¦¹¨ç¼Æªº¹Ï§Î¡G x=0:0.1:10; plot(x, myFun01(x));
1. ¼g¤@­Ó MATLAB ¨ç¼Æ piFun01.m ¨Ó­pºâ¤U¦C¯Å¼Æ¡G
f(n) = 4*(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ...)
2. ¨Ï¥Î tic ©M toc «ü¥O¨Ó´ú¶q piFun01(100000) ªº­pºâ®É¶¡¡C¦pªG§A¤£ª¾¹D¦p¦ó¨Ï¥Î³o¨â­Ó«ü¥O¡A½Ð¨Ï¥Î help tic ¤Î help toc ¨Ó¬d¥X¥¦­Ìªº¥Îªk¡C§ÚªºÂÂ¹q¸£¬O Pentium 450MHz¡A©Ò±oªº­pºâ®É¶¡¬ù¬° 2 ¬í¡C½Ð»¡©ú§Aªº¹q¸£³W®æ¥H¤Î¨ä­pºâ®É¶¡¡C
8. (**) Function for computing the Fibonacci number: The Fibonacci sequence is recursively defined as follows $$f_{n+2}=f_{n+1}+f_{n}$$ with $f_1=0$ and $f_2=1$.
1. Based on the above recursion, write a recursive function fibo01.m such that fibo01(n) returns $f_n$.
2. Based on the above recursion, write a non-recursive function fibo02.m such that fibo02(n) returns $f_n$.
3. Based on the following analytic solution of $f_n$, write a non-recursive function fibo03.m such that fibo03(n) returns $f_n$. $$f_n=\frac{\left(\frac{1+\sqrt{5}}{2}\right)^{n-1}-\left(\frac{1-\sqrt{5}}{2}\right)^{n-1}}{\sqrt{5}}$$
4. Plot the computing time of the above 3 functions when n goes from 1 to 30.
Hint: Use the commands tic and toc to measure the computing time. Try "help tic" and "help toc" in MATLAB command window to obtain more info on how to use these commands.
9. (**) Find the minimum of a matrix:
1. Write a MATLAB function minxy.m which can find the minimal element in a 2-dimensional matrix:
[minValue, minIndex] = minxy(matrix)
where matrix is a 2-d matrix, minValue is the minimal element of the input matrix, and minIndex is an integer vector of length 2 indicating the indices of the minimal element. (In other words, matrix(minIndex(1), minIndex(2)) is equal to minValue.) You can safely assume there is a unique minimum in the given matrix.
2. Test you program by typing the following statement in MATLAB command window:
[minValue, minIndex]=minxy(magic(20))
What are the returned values of minValue and minIndex?
1. ½Ð¼g¤@­Ó¨ç¼Æ minxy.m¡A¨ä¥\¯à¬O¥Ñ¤@­Ó¤Gºû¯x°}¤¤§ä¥X¤p¤¸¯À¡A¥Îªk¦p¤U¡G
[minValue, minIndex] = minxy(matrix)
¨ä¤¤ matrix ¬O¤@­Ó¤Gºû¯x°}¡AminValue «h¬O¨ä¤¸¯Àªº³Ì¤p­È¡A¦Ó minIndex ¬O¤@­Óªø«×¬° 2 ªº¥¿¾ã¼Æ¦V¶q¡A¥Nªí³Ì¤p­Èªº¯Á¤Þ¡C¡]´«¥y¸Ü»¡¡Amatrix(minIndex(1), minIndex(2)) ªº­È§Y¬O minValue¡C¡^§A¥i¥H°²³]¦b©Òµ¹ªº¯x°}¤¤¡A¥u¦s¦b¤@­Ó°ß¤@ªº³Ì¤p­È¡C

Hint
½ÐºÉ¶q¨Ï¥Î min «ü¥O¡C

## Part 2

1. What is the MATLAB command to display the version of the MATLAB you are using?
2. What is the MATLAB command to test the speed of your computer when executing MATLAB?
4. What is the MATLAB command to display the search path?
5. What is the MATLAB command to find the path of a command?
6. How do you add a folder to the search path of MATLAB?
7. How do you delete a folder from the search path of MATLAB?
8. What is the default data type of variables in MATLAB?
9. How do you create comments in a MATLAB program?
2. Create a magic matrix: Create a 5-by-5 magic matrix by hand. (You don't need to explain how you derive it.)
3. Vector indexing: Given two row vectors x and y of the same length, write a one-line MATLAB statement to achieve the following goals:
1. Change element 3 by multiplying it by 5.
2. Append an element of value 5.
3. Delete element 2.
4. Concatenate x and y.
5. Stack x and y.
4. Matrix indexing: Given a 5-by-5 matrix matrix A, write a one-line MATLAB statement to achieve the following goals:
1. Delete row 2 of A.
2. Delete rows 2 and 4 of A.
3. Delete column 3 of A.
4. Delete columns 3 and 5 of A.
5. Change row 4 of A by multiplying it by 5.
6. Change columns 1 and 4 of A by multiplying it by 3.
7. Switch columns 1 and 3 of A.
8. Switch columns 1 and 3, and rows 3 and 5, of A.
9. Replace column 3 by row 4.
10. Replace rows 2 and 4 by columns 1 and 5.
11. Assign a logical variable Y to verify sum of each column of A is equal to 65.
12. Assign a logical variable Y to verify sum of each row of A is equal to 65.
13. Assign a logical variable Y to verify the diagonal sum of A is equal to 65.
14. Assign a logical variable Y to verify the anti-diagonal sum of A is equal to 65.
15. Assign B to be columns 4, 2, and 5 of A.
16. Assign B to be the second to fourth elements of column 4 of A.
17. Assign B to be the concatenation of the third to fifth elements of column 4, and the first to fourth elements of column 5, of A.
18. Assign B to be the diagonal vector of A, without using "diag" command.
19. Assign B to be diag(A, -1), without using "diag" command. (This is, [23 6 19 2] for A=magic(5).)
20. Assign B to be diag(A, 1), without using "diag" command. (This is, [24 7 20 3] for A=magic(5).)
21. Put A at the upper left corner of a zero matrix of 7 by 7.
22. Put 5:14 into the first two columns of A.
23. Put 5:14 into the last two columns of A.
5. Simple indexing: What is the value of the variable d after executing the following script: a = [10 20;30 40]; b = [10 30;30 30]; c = a>b; d = a(c);
6. Simple math on matrices: Given a matrix A, write a one-line MATLAB statement to achieve the following goals:
1. Find the max. of each row.
2. Find the min. of each column.
3. Sort each row.
4. Sort each column in descending order.
5. Find the max. of min. of each column.
6. Find the max. of min. of each row.
7. Rotation and reflection: Given a n-vertex polygon denoted as a complex vector of n elements z=[z1, z2, ..., zn]. Use a few MATLAB statements to compute the coordinates of the polygon after the following operations.
1. Rotate p/6 with respect to the origin.
2. Rotate p/6 with respect to its center (which is the mean of all the vertices).
3. Reflection along a line q=p/3.
4. Flip the polygon along a straight of slope 1/2 which passes the polygon's center.
5. What is the rotation matrix? What is the reflection matrix?
8. Ackermann's function: ½Ð¨Ï¥Î MATLAB ¨Ó¼g¤@­Ó»¼°j¨ç¼Æ¥H­pºâ¤U¦C Ackerman's function¡G
A(m, n) =
 n+1, if m=0 A(m-1,1), if n= A(m-1, A(m,n-1)), otherwise
9. Transient points in a vector: A transient point in a vector is defined as a point which has a value between its left and right neighbors. Write a function transientPoint.m that return the indices of the transient points in a vector, with the following I/O format:
index=transientPoint(vec)
where "vec" is the input vector and "index" is a vector storing the indices to the transient points. (Note that the first and the last points are not qualified as transient points since they have only 1 neighbor. You can also safely assume elements in the given vector are unique.)

Here is a test example:

Example 1: 02-ªì±´MATLAB/transientPoint01.mvec=[-22 -68 7 -22 35 96 111 77 85 101 137 209 130 23 93 -10 -184 -260 -216 -85 -138 -159 -91 -165 -163 -35 -10 166 -33 -41 -85 -28]; index=transientPoint(vec); time=1:length(vec); plot(time, vec, '.-', time(index), vec(index), 'ro');

(English version) Write a function myAdd.m which can add two matrices with different dimensions, with the following usage:

where a and b are given 2D matrices, with perhaps different dimensions. Hence, it is not always possible to perform the common matrix addition. As an extension, myAdd can extend the given matrices to have the same dimensions (with minimum padded zeros), then add them to create the final output. For instance, when a = [1 2 3; 4 5 6] and b = [5; 2], myAdd(a, b) should return [6 2 3; 6 5 6]. Moreover, the function do not support scalar expansion, so myAdd([1, 1], 2¡^returns [3, 1] instead of [3, 3].
output = myMultiply(a, b)
12. Derivation of the Euler's number: This exercise is about the derivation of the Euler's number which is the base of the natural logarithm. The Euler's number is defined as follows: $$e = \lim_{n\rightarrow \infty} \left(1+\frac{1}{n}\right)^n$$
1. Give the formula of $(x+y)^n$ based on the binomial theorem.
2. Prove that e can be reformulated as follows: $$e = \frac{1}{0!} + \frac{1}{1!} + \frac{1}{2!} + \frac{1}{3!} + \cdots$$
13. Approximation of ln(1+r): This exercise is about the approximation of $ln(1+r)$.
1. Give the formula of the Taylor series expansion of a general well-behaved function $f(x)$ at $x=a$.
2. Use the expansion to explain why $ln(1+r)$ can be approximated by $r$ as $r$ is close to zero.
14. Computing the Euler's number (part 1): Let's assume the Euler's number e = 2.71828182845904523536.
1. Write a function to approximate the Euler's number by the following formula:
fun1(n) = (1+1/n)n
2. Plot the function as n goes from 1 to 1000.
3. Write a script to determine the smallest value of n such that |fun1(n) - e| < 10-5 ?
15. Computing the Euler's number (part 2): Let's assume the Euler's number e = 2.71828182845904523536.
1. Write a function to approximate the Euler's number by the following formula:
fun2(n) = 1/0! + 1/1! + 1/2! + 1/3! + ... + 1/n!
2. Plot the function as n goes from 1 to 100.
3. Write a script to determine the smallest value of n such that |fun2(n) - e| < 10-5 ?
16. Rule of 70:
1. Please explain what "Rule of 70" (also known as "Rule of 72" or "Rule of 69") is.
2. Please derive the exact formula for the above rule, assuming $ln(1+r) = r$ when $r$ is close to zero.
17. Computing for rule of 70: Please refer to the wiki page of Rule of 72 for this and all the following exercises.
1. Write a MATLAB program to plot the first table in the above wiki page, where x-axis is the rate from 0% to 70%, and y-axis is the no. of years for doubling the investment. The plot should have 6 curves, corresponding to columns 2 to 7 of the table.
2. Write a MATLAB program to plot the deviation from the actual years of doubling the investment.
18. Comparison of compounding at various frequencies: Please write a MATLAB script to generate the comparison plot shown here. (Hint: use "stairs" to plot a function in a stairwise manner.)
22. ¶R©Ð§ë¸êºëºâ: ½Ð¼g¤@­ÓMATLAB¸}¥»¡A¶i¦æ¤U¦C¹Bºâ¡C¡]Hint: You can use the functions "loan" and "saving" in the Utility Toolbox.¡^

¡]¦b¸Ñ¤W­z°ÝÃD®É¡A§Ú­Ì¤£¦Ò¼{³q³f¿±µÈµ¥¨ä¥¦¦]¯À¡A¨Ã°²³]»È¦æªº¦s´Ú§Q²v¥u¦³1.38%¡C¡^

Hint: My result for your reference...

¥H¤U­pºâ¥H¸U¤¸¬°³æ¦ì Monthly payment = 2.21839 Without rent income: Final value of the house = 2019.37 Final value of the monthly payments = 612.737 Final value of the down payment = 131.764 Final earning = 2019.37-612.737-131.764 = 1274.87 Initial earning = 967.54 With rent income: Final value of the monthly payments = 336.529 Final earning = 2019.37-336.529-131.764 = 1551.08 Initial earning = 1177.16
23. Function for computing IRR: Write a function to compute the IRR (Internal Rate of Return) of a given investment plan. A basic example for yearly compounding and yearly cash flow is shown next:
The new function has the following usage:
irr=myIrrFind(cashFlowVec, x0, 'timeUnit4cashFlow', 'timeUnit4compounding');
where
• irr: Internal rate of return
• cashFlowVec: Cash flow vector
• x0: Initial guess of IRR, default to 0
• timeUnit4cashFlow: Unit in month for cash flow, with the following possible values:
• 1: month
• 3: quarter
• 6: half year
• 12: year (default)
• timeUnit4compounding: Time unit compounding, with the following possible values:
• 'month' (default) for monthly compounding
• 'year' for yearly compounding (which is a valid option only when timeUnit4cashFlow is 12)
Note that if timeUnit4cashFlow is not 12 and timeUnit4compounding is 'year', the function should return nan.
MATLABµ{¦¡³]­p¡G¤Jªù½g