Professional Documents
Culture Documents
Exercise
Exercise
2. Use WHILE-loop to modify your script file in Q1 so that the error percentage for 𝑥𝑛 does not
exceed 5%.
3. Enter: format long. Use the function 𝑓(𝑥) = 𝑥 5 − 7 with starting point 𝑥0 = 2. By trial
and error, what is the lowest value of n for which the program converges (stops changing).
Compute the error, which is how close the program’s answer is to the true value. Compute the
residual, which is the program’s answer plugged into 𝑓. Are the error and residual zero?
5. Derive the Taylor series expansion for 𝑓(𝑥𝑖+1 ) = 𝑒 𝑥 sin 𝑥 using a base point at 𝑥𝑖 = 0 and
𝑥𝑖+1 = 0.2. Write a MATLAB program which takes 𝑥𝑖 as input and computes the series for up
to 10th order.
6. Use WHILE-loop to modify your script file in Q5 so that the error percentage does not exceed
0.1%.
Function
7. Create a function in a program file to convert Fahrenheit to Celsius.
8. Define a function in a file named average.m that accepts an input vector, calculates the
average of the values, and returns a single result.
9. Define a function in a file named stat.m that returns the mean and standard deviation of an
input vector.
10. Create a function file, named mymax.m and return the maximum of the five numbers given as
input.
11. Create a function file, named trapzz.m for Q4 and return the result.
12. Create a function file, named newRep.m for Q1 and return the result.