Whoop, yeah, I screwed it up. The reason it didn't work is because xi - naturallog = 0, since both xi and naturallog are set to xiplusone before evaluating the next while loop. Therefore the loop only runs once.
Try this.
function naturallog=natlog(y)
xi=1;
test = 1;
naturallog=xi-1+y*exp(-xi); //This calculates xiplusone the first time
while abs(test-naturallog)>.0001
test = naturallog; //this will store x(2,3,4... n) for the next while loop
naturallog=xi-1+y*exp(-xi); //This calculates x(3,4,5... n+1) for the next while loop
xi = naturallog; //This stores x(3,4,5...n+1) for while loop calculations after THAT.
end
end
Let me say this clearly one more time: the reason natlog is giving back 1.8384 is because that's the FIRST ITERATION OF
xiplusone=xi-1+y*exp(-xi). If you do natlog(5) and get 1.8384, it means the program is only running that line ONCE. So look in your code and say 'why isn't it doing it twice?'
I would suggest that if you're not too good at loops, try using For/Next loops. Whiles just suck.