Newtons method for matlab Ok so im trying to write a code for matlab and this is what i have so far:
function N = newton(f,x,a,m)
x=g;
numguess = 1;
x1 = g-(f(g)/(d(g));
numguess = 1+ numguess;
while numguess <m || (abs(x1-x))>=a
x1=x;
x2=x-(f(g))/d(g));
numguess = numguess +1;
end
if abs(x1-x)<=a
disp('You have hit the accuracy')
else
disp('You have reached the max number of guess')
end
*** the inputs have to be the function, and initial guess for the solution, desired accuracy and the max number of iterations allowed.
The user has to input the function as a symbolic function and use the symbolic toolbox to calculate the derivative.
**It has to iterate until the absolute value of the difference between the last two iterations is less than the desired tolerance/accuracy or
the maximum number of iterations have been reached. The output of your
function is the LAST iterate. |