Starting from:

$25

EE5003 - Module 6 - Loops and More on Function M-Files   - Solved

M6 Exercise 

Instructions
1.    The book has two different MATLAB® versions of Newton's method. One is a program (on page 162) and the other is a function (page 170). The comments on page 162 indicate the algorithm does not work on zero roots (i.e., it does not work when the true root is equal to zero). This is the case because of the form of "myrel".

o    Create a variation on the function m-file (page 170) in which the zero-root restriction is removed by changing the definition of "myrel." Specifically, do not divide by x; but leave the rest the same.

o    Then test your modified code on the MATLAB® pre-defined "sin" function (and remember your differential calculus: the derivative of sine is simply cosine).

o    Set the initial guess to pi/4. [You can still name the function "newtfun_LastName.m"].

o    Create a driver routine named "test_newtfun_LastName.m" that specifies the input arguments and calls newtfun_LastName.m.

2.    Do exercise 8.4 on page 194 of the textbook but do not create tables and do not sketch the results by hand. Instead, save the computed values in vectors and plot the results as indicated at the end of the description of the exercise.

o    NOTE: The temptation for the average programmer (especially in the context of a chapter titled ‘Loops") is to do this exercise using FOR loops. DON'T DO

IT! Use MATLAB®'s vectorization capability to make this exercise very simple. o Name your program "ex8p4_LastName.m".

3.    Do a variation of exercise 8.11 on page 192 of the textbook. Specifically, implement a function m-file called "mycos_LastName.m" that outputs four arguments:

1.    the approximation of cosine.

2.    the value obtained by MATLAB®'s built-in cosine function.

3.    the difference between the two (which should be less than 1e-4).

4.    a convergence flag (like the one used in newtfun_LastName.m). Test it on the following input values (in radians): 0, pi/4, pi/2, 3pi/4, pi


 

More products