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

Control Loop

1. For 𝑓(𝑥) = 𝑥 3 − 4 , perform 3 iterations of Newton’s method with starting point


𝑥0 = 2. Write a MATLAB script file using FOR-loop to compute the solution for this express.
Find the errors (compute the exact solution from calculator) and percentage errors of 𝑥0 , 𝑥1 , 𝑥2
and 𝑥3 .

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?

4. Write a script file to evaluate the following integral:


8
𝐸𝑣 = ∫ (3𝑥 2 − 1) d𝑥
2
where 𝑥 is the wavelength in cm. Estimate 𝐸𝑣 using Trapezoidal rule in MATLAB.

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.

You might also like