Matlab and Newtons method

Mar 2016

i have to to use newtons method to solve for a zero solution of f(x) = x-e^-x^-2.

I get the iteration formula: x(k+1) = xk - f(xk)/(f'xk) and a first guess that x(0) = 0.5.

can anyone help me write the code for the next iterations (does it contain a for loop?)

i am am new to calculus (kind of did it 20 years ago) and still learning Matlab (actually for my other unit!)

Any help appreciated

kind regards


MHF Helper
Jun 2008
North Texas
i have to to use newtons method to solve for a zero solution of f(x) = x-e^-x^-2.
f(x) = x-e^-x^-2 is interpreted as $f(x)=x-e^{-x^{-2}} = x - e^{-\frac{1}{x^2}}$

that's not the function you've referred to in your other posts re: the IVT & Newton's method

your function is f(x) = x - e^(-x^2) ... $f(x) = x - e^{-x^2}$

pay attention to detail to avoid further confusion.
Mar 2016

I seemed to have lost my reply to this post so; below is what I have tried to program by adapting an example we had in the notes. There is an issue in writing the formula (amongst other things). I did have it prompting me to input the initial guess and number of iterations however have seemed to have lost that and now get an error in the formula line. I have checked my indices and think they are now correct as pointed out above.

The question is:(a) Without doing a sketch, show that the equation f(x) = x − e^(−x^2)

has at least one solution on the interval [0, 2].
[Hint: Use a theorem discussed in lectures, or see Section 1.8 of Calculus (8th ed) by Stewart.
Ensure the conditions of the theorem are satisfied.]

(b) Use Newton’s method to find this zero accurate to 3 decimal places. You should include a
sketch of the function, Newton’s iteration formula, and the list of iterates. [Use a computer
if possible, e.g. a spreadsheet or MatLab.]

and the script I am trying to enter currently looks like this:
%Use Newtton's Method to find a non-zero number such that f(x) =
x_=input ('Enter initial guess x_0):');
num = input ('Enter number of iterations');
x = -0.1:0.001:2;
fprintf('x = %f\n', x);
for k=num
x = x-(x-e^(-x^2)/(1+2*x.e^(-x^2);
disp ('k num x')

Any help would be appreciated.

Last edited: