function anws=niuton(x0,eps)
x0=input('x0=');
eps=input('eps=');
x(1)=x0;
k=1;
h=fun1(x(1))
while(h<eps)
f1=fun1(x(k));
f2=fun2(x(k));
x(k)=x(k)-f1/f2;
k=k+1;
h=fun1(x(k));
end
x(k)
fun(x(k))
%%
function f= fun(x)
f=x^2-6*x+2
%%
function f1= fun1(x)
syms x;
y=sym('x^2-6*x+2');
f1=diff(y);
%f1=y1;
%%
function f2= fun2(x)
syms x;
y=sym('x^2-6*x+2');
y1=diff(y);
f2=diff(y1);
%f2=y2;
------解决方案--------------------------------------------------------
function f1= fun1(x)
syms x;
y=sym('x^2-6*x+2');
f1=diff(y);
%f1=y1;
这里求出来的是个式子,但是下面进行比较h<eps时就会报错!