How to find x values where y= 0 using newtons method and secant method?
Show older comments
I´ve drawn up newtons method in an easy function as:
function [x, iter] = newton(f, df, x)
maxiter = 1000;
iter = 0;
d = 100;
while abs(d) > sqrt(eps)*abs(x) && iter < maxiter
iter = iter + 1;
d = -f(x)/df(x);
x = x + d;
end
if iter == maxiter
disp('Maximum number of iterations performed. Answer is probably wrong.')
end
end
The secant method i've drawn up like this:
function [xout,iter] = sekant(f,x,x1)
iter = 0;
maxiter = 1000;
while abs(x1-x) > 1e-6
iter = iter + 1;
d = (f(x1) - f(x))./(x1-x);
xout = (x1-f(x1)./d);
x = x1;
x1 = xout;
if iter == maxiter
disp('No points of zeros found')
break
end
end
end
Here is my problem, I wish to put both of them together to find points where y = 0 for several functions as polynomials and differential eqations. My thought process has been that i need to find an interval of x values where these methods are used and with them make the inteval smaller untill im close enough to find the "approximation" or actual value of 0.
Accepted Answer
More Answers (0)
Categories
Find more on Nonlinear Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!