# create a function in MATLAB for approximating a root of a function using the Newton-Raphson method.

Question #2 – 8 Marks For this question your are going to create a function in MATLAB for approximating a root of a function using the Newton-Raphson method. You can use your Bisect.m function M-File for the Bisection Method as a template. You will then use your Newton function to solve an engineering problem from the textbook. (a) (2 points) Write a MATLAB function M-file for Newton’s method corresponding to the following pseudocode: function root = Newton( 20, €, imax ) it1 output heading while i < imax root + 20 – f(20)/f'(:30) output i, root if |1 – Xo/root| < € return end if it i+1 root end while output “failed to converge” Use the following (or similar) MATLAB print statements for output. fprintf ( iteration approximation \n’) fprintf (” %6.0f %18. 8f \n’, i, root ) fprintf ( ‘ failed to converge in %g iterations\n’, imax ) Pass the additional parameters f and fp for f and f’ and use the function handle Qfunctionname to pass the functions. (similar to the way f was a parameter in the bisection function in my code). DELIVERABLES: A copy of your MATLAB M-file as part of your PDF. 3 (b) (2 points) A catenary is the curve formed by a hanging cable. Considering a Cartesian coordinate system in the (2, y)-plane, suppose that the lowest point of a catenary is at the origin (0,0). Then, the formula for the catenary that hangs from the two points (a,b) in the (x, y)-plane is b = ccosh(a/c) – C for some constant c. Determine the value of c for the catenary that passes through the points (15,4). You will need to write MATLAB function M-files with headers something like function y = fQ2b(x) and function y = fpQ2b(x) corresponding to the function f(c) that you are computing a zero of, and its derivative TOP SURG ame” f'(2), which you will need to determine using calculus. DELIVERABLES: Copies of your M-files for the function and its derivative in your PDF. (c) (2 points) Use the MATLAB function M-file Newton, from (a), with 20 = 10, € = 10-8, and imax=20 to solve the problem in Q2(b). Remember, you cannot pass the functions f(x) and f'(2) directly as arguments to the Newton function. You should use function handles. DELIVARABLES: Provide the call you used and the output of the function. (d) (2 points) Use the MATLAB function ezplot to draw a graph of the above catenary on the interval -15, 15). The following MATLAB statement illustrates the syntax of ezplot (this is not the input for your question!): ezplot(‘exp(-x)+cos(pi*x)’, (-1, 5 ] ) This example will cause a graphics window to open and display the graph of the function e-* + cos(Tu) on the interval (-1,5). DELIVERABLES: Your MATLAB input commands and the corresponding plot.

## How it works

You are only 4-steps away from a perfect custom essay.

### GET A FREE QUOTE

Price: \$ MyEssayWritersonline.com

MyEssayWritersonline.com helps students cope with college assignments and write papers on a wide range of topics. We deal with academic writing, creative writing, and non-word assignments.

Copyright @ 2004 – 2020, MyEssayWritersonline.com.