50 likes | 267 Views
习题评述. 在计算 Seidel 的迭代法的收敛性时. f(3)= -0.9107. f (3)= 0.2440. 关于牛顿迭代法的程序. function z=newton(f,x0,y0,e) x = sym('x'); y=sym('y') Jx=det([diff(f,y,1),f]); Jy=det([f,diff(f,x,1)]); J=det([diff(f,x,1),diff(f,y,1)]); x=x0; y=y0; n=1 x1=x0+ eval (Jx)/ eval (J); y1=y0+ eval (Jy)/ eval (J);
E N D
习题评述 • 在计算Seidel 的迭代法的收敛性时
关于牛顿迭代法的程序 function z=newton(f,x0,y0,e) x = sym('x'); y=sym('y') Jx=det([diff(f,y,1),f]); Jy=det([f,diff(f,x,1)]); J=det([diff(f,x,1),diff(f,y,1)]); x=x0; y=y0; n=1 x1=x0+eval(Jx)/eval(J); y1=y0+eval(Jy)/eval(J); while abs(x1-x0)>e & abs(y1-y0)>e & n<1000 x0=x1; y0=y1; x=x1; y=y1; n=n+1; x1=x0+eval(Jx)/eval(J); y1=y0+eval(Jy)/eval(J); end x=x1; y=y1; eval(f), z=[x1,y1,n];
function f=myfun1 syms x; syms y f=[x^2+y^2-1;x^3-y]; newton(myfun1,0.8,0.6,1e-6) ans = 1.0e-011 * 0.1267 0.2556 ans = 0.8260 0.5636 3.0000