# matlab迭代输出过程详解,用MATLAB对高斯赛德尔迭代法仿真,怎样把解x1,x2,x3输出在同一坐标系中,怎样输出每一次迭代值....

A = [4 -1 1; 4 -8 1; -2 1 5];

b = [7; -21; 15];

x0 = zeros(3,1);

eps=1.0e-7;

D=diag(diag(A));%求A的对角矩阵

L=-tril(A,-1);%求A的下三角阵

U=-triu(A,1);%求A的上三角阵

G=(D-L)U;

f=(D-L)b;

Y = [1 zeros(1,3)];

y=G*x0+f;

n=1;%迭代次数

while norm(y-x0)>=eps

x0=y;

y=G*x0+f;

n=n+1;

Y(n,:) = [n y'];

end

% 生成图4.2

plot(Y(:,1),Y(:,2:4))

axis([1 12 0 5])

grid on

set(gca,'xtick',2:2:12,'ytick',0:5)

% 输出表4.2

fprintf('%it%.14ft%.14ft%.14fn',Y.')

1 0.00000000000000 0.00000000000000 0.00000000000000

2 1.87500000000000 3.93750000000000 2.96250000000000

3 1.99375000000000 3.99218750000000 2.99906250000000

4 1.99828125000000 3.99902343750000 2.99950781250000

5 1.99987890625000 3.99987792968750 2.99997597656250

6 1.99997548828125 3.99998474121094 2.99999324707031

7 1.99999787353516 3.99999809265137 2.99999953088379

8 1.99999964044189 3.99999976158142 2.99999990386047

9 1.99999996443024 3.99999997019768 2.99999999173256

10 1.99999999461628 3.99999999627471 2.99999999859157

A = [4 -1 1; 4 -8 1; -2 1 5];

b = [7; -21; 15];

x0 = zeros(3,1);

eps=1.0e-7;

D=diag(diag(A));%求A的对角矩阵

L=-tril(A,-1);%求A的下三角阵

U=-triu(A,1);%求A的上三角阵

G=(D-L)U;

f=(D-L)b;

% Y = [1 zeros(1,3)];

n=1;%迭代次数

while true

Y(n,:) = [n x0'];

y=G*x0+f;

if norm(y-x0)n=n+1;

x0=y;

end

1 0.00000000000000 0.00000000000000 0.00000000000000

2 1.75000000000000 3.50000000000000 3.00000000000000

3 1.87500000000000 3.93750000000000 2.96250000000000

4 1.99375000000000 3.99218750000000 2.99906250000000

5 1.99828125000000 3.99902343750000 2.99950781250000

6 1.99987890625000 3.99987792968750 2.99997597656250

7 1.99997548828125 3.99998474121094 2.99999324707031

8 1.99999787353516 3.99999809265137 2.99999953088379

9 1.99999964044189 3.99999976158142 2.99999990386047

10 1.99999996443024 3.99999997019768 2.99999999173256

1年前

2

• 0
点赞
• 1
收藏
觉得还不错? 一键收藏
• 0
评论
03-29 1963
03-01 694
02-08 5793
05-06 2457
05-05 1746

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。