Hi ,
I am trying to make newtons Method work.
I want it to work in a specific way , somthing like this
[s,fc] = mynewton (@somethingfunction,1,10^-4);
function [fv , fpv ] = somethingfunction(x)
% MYFUN Function to test Newton
%
fv = x^2 - 10;
fpv = 2*x;
end
function [x ]= mynewton (somethingfunction,x0 , tol )
fncon=1;
[f(1), g(1)] = myfun(x0);
s(1)=x0 ;%nitial point
for i=1:1000 %it should be stopped when tolerance is reached
[f(i), g(i)] = myfun(s(i));
s(i+1) = s(i) - f(i)/g(i);
if( abs(s(i+1)-s(i)/s(i))>tol) % tolerance
disp(double(s(i+1)));
break
end
end
if fncon
fprintf(' %16.16f \n',s(end))
end
end

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 7 de Jun. de 2020

0 votos

Condition should be
if(abs(s(i+1)-s(i)/s(i))<tol)
% ^ less than operator

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Preguntada:

el 7 de Jun. de 2020

Editada:

el 7 de Jun. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by