MATLAB线性方程组Jacobi迭代法 GaussSeidel迭代法源代码.doc

上传人:土8路 文档编号:10084723 上传时间:2021-04-18 格式:DOC 页数:5 大小:37KB
返回 下载 相关 举报
MATLAB线性方程组Jacobi迭代法 GaussSeidel迭代法源代码.doc_第1页
第1页 / 共5页
MATLAB线性方程组Jacobi迭代法 GaussSeidel迭代法源代码.doc_第2页
第2页 / 共5页
MATLAB线性方程组Jacobi迭代法 GaussSeidel迭代法源代码.doc_第3页
第3页 / 共5页
MATLAB线性方程组Jacobi迭代法 GaussSeidel迭代法源代码.doc_第4页
第4页 / 共5页
MATLAB线性方程组Jacobi迭代法 GaussSeidel迭代法源代码.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《MATLAB线性方程组Jacobi迭代法 GaussSeidel迭代法源代码.doc》由会员分享,可在线阅读,更多相关《MATLAB线性方程组Jacobi迭代法 GaussSeidel迭代法源代码.doc(5页珍藏版)》请在三一文库上搜索。

1、MATLAB线性方程组Jacobi迭代法 Gauss-Seidel迭代法源代码1.熟悉迭代法,并编写程序 matlab程序按照算法(Jacobi迭代法)编写Matlab程序(Jacobi.m)function x, k, index=Jacobi(A, b, ep, it_max)% 求解线性方程组的Jacobi迭代法,其中% A - 方程组的系数矩阵% b - 方程组的右端项% ep - 精度要求。省缺为1e-5% it_max - 最大迭代次数,省缺为100% x - 方程组的解% k - 迭代次数% index - index=1表示迭代收敛到指定要求;% index=0表示迭代失败if

2、 nargin 4 it_max=100; endif nargin 3 ep=1e-5; endn=length(A); k=0; x=zeros(n,1); y=zeros(n,1); index=1;while 1 for i=1:n y(i)=b(i); for j=1:n if j=i y(i)=y(i)-A(i,j)*x(j); end end if abs(A(i,i)1e-10 | k=it_max index=0; return; end y(i)=y(i)/A(i,i); end if norm(y-x,inf)=errorBound & stepmaxSpx0=inv(D

3、)*(L+U)*x0+inv(D)*b;vChain(k,:)=x0;k=k+1; error=norm(x0-fx0); fx0=x0; step=step+1;endv=x0;sN=step; 用Gauss-Seidel迭代法求解上题的线性方程组,取 。输入:A=4 3 0;3 3 -1;0 -1 4;b=24;30;-24;x0=0;0;0;v,sN,vChain=gaussSeidel(A,b,x0,0.00001,11)输出:v = 0.6169 11.1962 -4.2056sN = 11vChain = 6.0000 10.0000 -6.0000 -1.5000 2.0000 -3.5000 4.5000 10.3333 -5.5000 -1.7500 3.6667 -3.4167 3.2500 10.6111 -5.0833 -1.9583 5.0556 -3.3472 2.2083 10.8426 -4.7361 -2.1319 6.2130 -3.2894 1.3403 11.0355 -4.4468 -2.2766 7.1775 -3.2411 0.6169 11.1962 -4.2056 0 0 0 0 0 0 0 0 0 0 0 0

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1