Answered step by step
Verified Expert Solution
Question
1 Approved Answer
MatLab code Newton's Method is another root-finding algorithm which uses a function's gradient to converge to the location of the root. The main looping structure
MatLab code
Newton's Method is another root-finding algorithm which uses a function's gradient to converge to the location of the root. The main looping structure is similar to the bisection method, however the mathematical process is slightly different. For this approach we need to follow these steps: Choose an initial guess, to, and solve the function f(x) and the function derivative f (xo). Calculate the new point based on the gradient: x1 = Xo - f (x)/(x). Check if the value of f(x 0 to within a specified tolerance tol. If the function value is above the tolerance, repeat the steps above with the new value of x, i.e.: f(x). f (n) and Xx+1. You are required to use Newton's method to find a root of the equation; f(x) = x - 3+1 You should implement your solution as a function, which accepts the inputs: x0 = 1.5% starting point nMax = 15 % max number of iterations tol = le-4; % largest acceptable absolute value of f(x1) = 0 Your code should output the converged root of the equation xt. You can test your code with the above inputs before submitting to confirm the code performs correctly. A random starting point for xo will then be entered into your function which will be checked to pass. Function Reset MATLAB Documentation 1 function (x1) = tutorial1(x0, nMax, tol) 2% Calculate the root of the function f(x) = x^3 - 3^x + 1 3% using the Newton Method of root-finding. 4 % Inputs: 5 % - x0 initial guess 6 % - nMax number of iterations 7 % - tol solution accuracy tolerance 8 % Output: 9 % - X1 converged root of the equation 10 11 Function Reset DI MATLAB Documentation 1 function [x1] = tutoriali(x0, nMax, tol) 2% Calculate the root of the function f(x) = x^3 - 3^x + 1 3% using the Newton Method of root-finding. 4 % Inputs: 5 % initial guess 6 % nMax number of iterations 79 tol solution accuracy tolerance 8% Output: 9 % X1 converged root of the equation 10 11 12 % Sample output code for monitoring this should be included in your loop structure. 13 fprintf('Iteration = $d, x0 = %.4f, x1 = $.4f, fx1 = %.4f ', i,x0, x1, fx1); 14 15 return 16 Code to call your function C Reset 1 X0 = 1.5; 2 nMax = 5; 3 tol = le-4; 4 x1 = tutoriali(x0, nMax, tol)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