
clc,clear

m = 2; % 根的重数
x0 = 1.5; % 初值
syms x
f = x^4 - 4*x^2 +4;
fp = diff(f);
mu = f/fp;

phi1 = x - mu;
phi2  = x - m*mu;
phi3  = x - mu/diff(mu);

x1 = x0;
x2 = x0;
x3 = x0;


for n = 1:5
    
    x1 = subs(phi1,x1);
    x2 = subs(phi2,x2);
    x3 = subs(phi3,x3);
    
    fprintf('第 %d 步\n Newton法：xk=%g, f(xk)=%g\n 改进Newton法：xk=%g, f(xk)=%g\n 等价方程法：xk=%g, f(xk)=%g,\n\n',...
             n,x1,subs(f,x1),x2,subs(f,x2),x3,subs(f,x3));
    
end