Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use help sprintf and help disp in Matlab to understand how to use sprintf and disp to display the data. Here is an example: disp(sprintf('I
Use "help sprintf" and "help disp" in Matlab to understand how to use "sprintf" and "disp" to display the data. Here is an example: disp(sprintf('I have n=%d and x=%g but f=%f. ', 2, 1.22, 1.22)) This will give the following result in Matlab: I have n = 2 and x = 1.22 but f = 1.220000. Write a Matlab function for Newton's method. Your file mynewton.m should start with: function x = mynewton(f, df, x0, to1, nmax) Among the input variables, f, df are the function f and its derivative f', x0 is the initial guess, to1 is the error tolerance, and nmax is the maximum number of iterations. The output variable x is the result of the Newton iterations. Use sprintf and "disp" to display your result in each iteration so you can check the convergence along the way. First, test your function with Example 5.7 in Section 5.4, computing squareroot 2. Then, use your Matlab function to find a root of f(x) = e^-x - cos(x) on the interval [1.1, 1.6]. Use to1 = 1e = 12 and nmax = 10. You should choose an initial guess x_0 on the interval [1.1, 1.6]. What is your answer? What to hand in: Print out your files mynewton.m, files for functions f(x) and f'(x), script file, test result for the example of squareroot 2 and for the root of f(x) = e^-x - cos(x)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started