# Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any a...

Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any arbitrary function f given an initial guess xo, an absolute error tolerance e and a maximum number of iterations max.iter. Follow mynewton.m template posted in homework 2 folder on TritonED for guidance. You are not required to use the template. The function should return the approximated root n and the number of steps n taken to reach the solution. Use function mynewton.m to perform the following exercises. (a, b) Find the root of f(z)2 3r2 - 36 31 with o 1.5, e 10-3 and a maximum number of iterations equal to 25. Put the root in p4a and the corresponding number of steps in p4b (c. d) Find the root of f(z-2x3+3x2-36x +31 with z,-2, e 10-3 and a maximium number of iterations equal to 250. Put the root in p4c and the corresponding number of steps in p4d

MATLAB Code:

close all
clear
clc

f = @(x) 2*x^3 + 3*x^2 - 36*x + 31; % Input Function

x0 = 1.5; tol = 1e-3; max_iter = 25;
[p4a, p4b] = newton(f, x0, tol, max_iter)

x0 = 2; tol = 1e-3; max_iter = 250;
[p4c, p4d] = newton(f, x0, tol, max_iter)

function [x,n] = newton(f, x0, tol, max_iter)
n = 0;
x = x0;
h = 1e-6;
while true
n = n + 1;
fd = (f(x + h) - f(x - h)) / (2*h); % Central finite difference of f at x
x = x - f(x)/fd; % Newton update
if n >= max_iter || abs(f(x)) < tol % Termination condition
break;
end
end
end

Output:

p4a =
1.0000
p4b =
4
p4c =
2.8807
p4d =
56

##### Add Answer of: Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any a...
More Homework Help Questions Additional questions in this topic.

• #### the square root of 3 times the square root of 15 also the square root of 18 times the square root of 3 To multiply square roots: sq rt of z times the sq rt of y It would be the square root of zy The first one is 3x15 = 45 So it's the squar

Need Online Homework Help?