maplex11

15 Reputation

4 Badges

1 years, 135 days

MaplePrimes Activity


These are questions asked by maplex11

hi i am trying to create a procedure for newton rhapson method, which finds roots of a function. the first procedure i made work but now i want it to show an error message for when the function diverges at x0 and when the derivative at x0 = 0. can someone pls advise me how to fix it? thank you:)

NM1 := proc(f, xold)
    local x1, x0, precision;
    x0 := xold;
    x1 := evalf(x0 - f(x0)/D(f)(x0));
    precision := 10^(-3);
        if limit(f,(x0)) = 0 then
            error("Newton's Method cannot do the calculation");
        end if;
        if D(f)(x0) = 0 then
            error("Newton's Method cannot do the calculation");
        else
        while abs(x1-x0) > precision do
            x0 := x1;
            print(x0);        
            x1 := evalf(x0 - f(x0)/D(f)(x0));            
        end do;
        end if;

   return x1;
end proc:

Page 1 of 1