1、 基于java实现电子时钟 迭代法求两点边值问题(一)摘要当今的环境下,数值计算越来越依赖于计算机。大规模科学计算和工程技术中许多问题的解决,最终归结为大型稀疏线性方程组的求解,其求解时间在整个问题求解时间中占有很大的比重,有的甚至达到80%。由于现今科学研究和大型项目中各种复杂的可以对计算精度和计算速度的要求越来越高。因此,作为大规模科学计算基础的线性代数方程组的高效数值求解引起了人们的普遍关注。这种方程组的求解一般采用迭代法。这次我做的迭代法求两点边值问题就是通过MATLAB来实现的。关于迭代法,是有很多种解决公式的:Jacobi,G-S和超松弛迭代法。这三种方法的原理大致相同,jacob
2、i需要给定初向量,G-S则需要给定初值,超松弛法是对Guass-Seidel迭代法的加权平均改造。而本文则是对大型稀疏线性方程组迭代求解与三种迭代法(Jacobi,Gauss-Seidel和超松弛迭代法)的收敛速度与精确解的误差比较做出研究。关键词:数值计算 迭代法 三种公式ITERATION METHOD FOR TWO-POINT BOUNDARY VALUE PROBLEMSABSTRACTTodays environment, numerical computation is more and more dependent on the computer. Many problems
3、in the large-scale scientific computing and engineering solution, ultimately comes down to solving large sparse system of linear equations, the solution time occupies a large proportion in the whole problem solving time, some even reached 80%. Due to the current scientific research and large project
4、s in various complex can claim to the computing precision and computing speed is higher and higher. Therefore, the linear algebraic equations, which is the basis for large-scale scientific computing efficient numerical solution has attracted widespread attention. To solve the general iterative metho
5、d is used to this kind of equations. This time I do the iteration method of two-point boundary value problem is accomplished by MATLAB.About the iteration method, there are many kinds of solution formula is: Jacobi, G - S and over relaxation iteration method. The principles of these three methods ar
6、e roughly the same, Jacobi need at the beginning of a given vector, G - S requires the given initial value, a super relaxation method is weighted average of the transformation of Gauss - Seidel iterative method. And this article is for iteration solving large sparse linear equations with three kinds
7、 of iterative method (Jacobi, Gauss - Seidel and over relaxation iteration method) the error between the convergence speed and the exact solution of comparative research.Key words: numerical calculation iterative method three kinds of formula目 录1 课程目的与要求11、1课程目标11、2 课程的实现环境12 概要设计23 详细设计54 测试结果与心得体会
8、85 参考文献15附录16源程序代码164 1 课程的目的与要求1、1课程目标利用我们所学的数值分析的迭代法知识对线性方程组的问题进行求解,同时把迭代法的求解过程用MATLAB程序语言实现其算法功能。对实验结果进行记录,对比与分析最后得出结论。1、2课程的实现环境硬件要求能运行Windows9.X操作系统的微机系统、Matlab软件。2概要设计2、1迭代法简介1.Jacobi迭代法:对于非奇异线性方程组Ax=b,令A=D-L-U,其中则原方程组可改写为: (2.2)其中给定初始向量:由(2.2)可以构造迭代公式:其分量形式为:2. Guass-Seidel迭代法:类似于Jacobi迭代法,给定
9、初值:令则得到Guass-Seidel公式:其分量形式为:3.超松弛迭代法(SOR 迭代法):SOR迭代法是对Guass-Seidel迭代法的加权平均改造,即为Guass-Seidel迭代解,即它的分量形式为:其中称为松弛因子,当1时称为超松弛;当 clear x=linspace(0,1);truy=(1-0.5)/(1-exp(-1/1)*(1-exp(-x./1)+x.*0.5;figure;plot(x,truy,g,LineWidth,1.5);hold on;Grid图:4测试结果与心得体会4、1程序运行情况Jacobi法:代码见附录Eps=1结果:迭代次数k:22273结果与精确
10、解的比较图(绿色粗线是精确解,黑色细线是迭代结果)Eps=0.1结果:迭代次数k:8753结果与精确解的比较图(绿色粗线是精确解,黑色细线是迭代结果)Eps=0.01结果:迭代次数k:661结果与精确解的比较图(绿色粗线是精确解,黑色细线是迭代结果)G-S迭代法:代码见附录Eps=1结果:迭代次数k:11125结果与精确解的比较图(绿色粗线是精确解,黑色细线是迭代结果)Eps=0.1结果:迭代次数k:4394结果与精确解的比较图(绿色粗线是精确解,黑色细线是迭代结果)Eps=0.01结果:迭代次数k:379结果与精确解的比较图(绿色粗线是精确解,黑色细线是迭代结果)超松弛法:代码见附录Eps=
11、1 w=1.56结果:迭代次数k:3503结果与精确解的比较图(绿色粗线是精确解,黑色细线是迭代结果)Eps=0.1 w=1.56结果:迭代次数k:1369结果与精确解的比较图(绿色粗线是精确解,黑色细线是迭代结果)Eps=0.01 w=1.56结果:迭代次数k:131结果与精确解的比较图(绿色粗线是精确解,黑色细线是迭代结果)4、2三种方法的比较Jacobi、G-S、超松弛法,三者都能够取得对精确解的良好逼近,但是,在相同的精度条件下,三者的收敛速度是不一样的,jacobiG-S超松弛,也就是说,在迭代次数相同的条件下,精度:jacobiG-Sj L(i,j)=-A(i,j);end end
12、endU=zeros(n-1);for i=1:n-1 for j=1:n-1 if ij U(i,j)=-A(i,j); end endendB=D(L+U);g=Db;while 1 z=B*y+g; if norm(z-y,inf)j L(i,j)=-A(i,j);end endendU=zeros(n-1);for i=1:n-1 for j=1:n-1 if ij U(i,j)=-A(i,j); end endendB=D(L+U);g=Db;while 1 z=(D-L)U*y+(D-L)b; if norm(z-y,inf)j L(i,j)=-A(i,j);end endendU
13、=zeros(n-1);for i=1:n-1 for j=1:n-1 if ij U(i,j)=-A(i,j); end endendB=D(L+U);g=Db;Lw=(D-w*L)-1)*(1-w)*D+w*U);while 1 z=Lw*y+w*(D-w*L)-1*b; if norm(z-y,inf)delta break; end y=z;k=k+1;end x=linspace(0,1);truy=(1-a)/(1-exp(-1/eps)*(1-exp(-x./eps)+x.*a;figure;plot(100*x,truy,g,LineWidth,5);hold on;gridhold on;plot(y,b)第 21 页 共 23 页