I was creating this code for the "Müller Method" for Numerical Analysis. Everything works fine till the if (for getting the x3) goes on. The problem is, the Maple doesn't detects the if.
I tried checking every variable and every variable is calculated except "x3"; even "disc".
I would like to know what happened. Anyways, here's the code:
x0 := 0; x1 := 8.4; x2 := 10; iter := 1000; tol := 10^(-8); f := proc (x) options operator, arrow; 3*x^3+7*x^2+x+2 end proc; f(x); plot(f(x), color = green); printf(" n x0 x1 x2 x3 Error \n"); for i to iter do d0 := evalf((f(x1)-f(x0))/(x1-x0)); d1 := evalf((f(x2)-f(x1))/(x2-x1)); h1 := evalf(x2-x1); h0 := evalf(x1-x0); a := evalf((d1-d0)/(h1-h0)); b := evalf(a*h1+d1); c := evalf(f(x2)); disc := sqrt(-4*a*c+b^2); if abs(b+disc) > abs(b-disc) then x3 := x2+(-2*c)*(1/(b+sqrt(-4*a*c+b^2))); erry := abs((x3-x2)/x3) else x3 := x2+(-2*c)*(1/(b-sqrt(-4*a*c+b^2))); erry := abs((x3-x2)/x3) end if; if erry > tol then x0 := x1; x1 := x2; x2 := x3; printf("%2d %2.8f %2.8f %2.8f %2.5 f %2.8 f \n", i, a, b, c, x3, erry) else printf("una raiz es: %2.8f ", x3); break end if end do;
I put the image (as it looks on my maple) and the "code" so you can copy-paste it in Maple.