Consider the following sequence:

x1 = 1

xi+1 = xi - 1 + y * e-xi (That's e to the power -xi. Note the minus sign.)

Note that ea is written as exp(a) in matlab.

For this series, xi converges on loge(y). E.g., if y =1, xi gets closer and closer to 0 as i gets larger. Also, xi-1 and xi get closer and closer together. Write a function named natlog that takes y as its argument, computes xi for i starting at 1 and continuing until abs(xi-1-xi) < .0001. Natlog should return the final value of xi as its value.

Here is my function, but it doesn't make sense..i.e. for natlog(5), it gives 1.8384 and it returns values of natlog for negative numbers....I'm not sure if it's supposed to give the same answers as ln(some number), but yeah...can anyone help me fix my program?

function naturallog=natlog(y)

xi=1;

xiplusone=xi-1+y*exp(-xi)

while abs(xi-xiplusone)<.0001&&xi>=1;

naturallog=naturallog+1

end