I would like to implement the following: ive written a script that executes the Newton Raphson algorithm for my specific function. Now I would like to write a script that repeats itself using the previous found zero as my next intial starting point:
x=zeros(1,31);
for i=1:31
x(i)=(i-1)/10;
end
y0=0;
for i=1:length(x)
y0=newton(x(i),y0)
end
So, I want this script to execute newton(x,y0). So it will start with newton(0,0), it will find a new value y0 and then I want the script to execute newton(0.1,y0) etc. I want these values to be displayed in a table together with the number of iterates that was needed to find the value y0.
I hope my question is clear. Thanks in regards.
Again: I have a vector x with elements 0, 0.1, 0.2, ...,3 When I implement x(i) with initial value y0 newton(x,y) will give me a value. Then I want the script to execute newton(x,y) again with value x(2) for x and the previous found y0.So I need some kind of loop, but I can't get it done .. :(
EDIT
This is my newton
-function:
function nulpunt=newton(x,y0)
tolerantie=1e-8;
iteraties=0;
while (abs(functie1(y0,x))>tolerantie)
y0=y0-functie1(y0,x)/afgeleide_functie1(y0);
iteraties=iteraties+1;
end
if iteraties==100;
fprintf('Maximaal aantal iteraties bereikt')
else
fprintf('De benadering van het nulpunt y*(%.2f) is %.4f gevonden in %d iteraties.\n',x,y0,iteraties)
end
end