|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
function x=demoSSub(maxit,x0)
% demoSSub Solve a 2-by-2 nonlinear system by successive
% The system is
% 1.4*x1-x2=0.6
% x1^2-1.6*x1-x2=4.6
%
% Symopsis: x=demoSSub(maxit,x0)
%
% Input: maxit=(optional)max number of iterations. Default:maxit=5
% x0=(optional)initional guess at solution. Default: x0=[0;0]
%
% Output: x=extimate of solution after maxit iterations
if nargin<1
maxit=5
end
if nargin<2
x0=zeros(2,1)
end
%----Coefficients for the case of two distinct solutions
alpha=1.4;beta=-0.6;sigma=-1.6;tau=-4.6;
b=[-beta;-tau];
x=x0;
fprintf('\n k x(1) x(2) norm(f)\n');
for k=1:maxit
A=[alpha -1;(x(1)+sigma) -1];
f=A*x-b;
x=A\b;
fprintf('%4d %9.5f %9.5f %10.2e\n',k,x(1),x(2),norm(f));
end
以上是编制的程序
x=demoSSub(10,[-1;-2])
k x(1) x(2) norm(f)
1 -1.00000 -2.00000 1.11e-016
2 -1.00000 -2.00000 3.33e-016
3 -1.00000 -2.00000 1.11e-016
4 -1.00000 -2.00000 3.33e-016
5 -1.00000 -2.00000 1.11e-016
6 -1.00000 -2.00000 3.33e-016
7 -1.00000 -2.00000 1.11e-016
8 -1.00000 -2.00000 3.33e-016
9 -1.00000 -2.00000 1.11e-016
10 -1.00000 -2.00000 3.33e-016
x =
-1
-2
x=demoSSub(10,[4;5])
k x(1) x(2) norm(f)
1 4.00000 5.00000 3.33e-016
2 4.00000 5.00000 3.33e-016
3 4.00000 5.00000 3.33e-016
4 4.00000 5.00000 3.33e-016
5 4.00000 5.00000 3.33e-016
6 4.00000 5.00000 3.33e-016
7 4.00000 5.00000 3.33e-016
8 4.00000 5.00000 3.33e-016
9 4.00000 5.00000 3.33e-016
10 4.00000 5.00000 3.33e-016
x =
4
5
x=demoSSub(10,[5;5])
k x(1) x(2) norm(f)
1 2.00000 2.20000 7.53e+000
2 -4.00000 -6.20000 6.00e+000
3 -0.57143 -1.40000 2.40e+001
4 -1.12000 -2.16800 1.96e+000
5 -0.97087 -1.95922 6.14e-001
6 -1.00733 -2.01027 1.45e-001
7 -0.99817 -1.99744 3.67e-002
8 -1.00046 -2.00064 9.15e-003
9 -0.99989 -1.99984 2.29e-003
10 -1.00003 -2.00004 5.72e-004
x =
-1.0000
-2.0000
(这个就不太明白了,为什么结果不收敛于(4,5)?)
请教各位高手,谢谢 |
|