《数值计算方法FORTRAN程序》由会员分享,可在线阅读,更多相关《数值计算方法FORTRAN程序(17页珍藏版)》请在金锄头文库上搜索。
1、数值计算方法FORTRAN程序一函数插值和方程组求解目录数值计算方法FORTRAN程序一函数插值和方程组求解1一.函数插值1二 齐次线性方程组的直接法求解2三 齐次线性方程组的迭代求解法4附录一:流程图7序序序序序序序序序序序序 呈呈呈呈呈呈呈呈呈呈呈呈四.五.六.七.八.九十十一 十二Lagnmge插值Newton向前插值Newton向后插值Gauss列主元消去法、Crout (Dolittle)三角分解法、LDlJ、LL7主程序Gauss列主元消去法子程序Doolittle三角分解子程序LDU子程序LL7子程序Jacobi、 GaussSMdel迭代法主程序Jacobi迭代法子程序Gaus
2、sSeidel迭代法子程序SOR法主程序及子程序101011111212131313141415一. 函数插值对11+1个节点X及yi=f(x】)(I=0丄.工),编制通用程序。1) n次Lagrange插值计算公式Ln(x);A)流程图(图1、2)B)程序(程序一)C)计算实例输入数据文件:mputl.datKNOWN NODES NUMBER AND NODE X WITH Y(X)WANT TO BE KNOWN:42.5NODES XI AND YI WHICH ARE ALREADY KNOWN:1.0003.0004.0002.0001.00027.00064.0008.000输出
3、数据文件:outputl.datResults of Lagrange mteipolation at point x is:Ln(x)= 15625000000000000D) 结果分析实际计算数次插值,分析可见:在4节点插值时,对于四次以下的函数的插值具有很精确的结果,但对四次 及以上的函数的插值,随阶次升高,插值精度降低。i 吕 毅宁:2)n次Newton向前插值计算公式;A)流程图(图3)E)程序(程序二)C)计算实例输入数据文彳牛:iiiput2.datKNOWN NODES NUMBER AND NODE X WITH Y(X)WANT TO EE KNOWN: 42.5NODES
4、 XI AND YI WHICH ARE ALREADY KNOWN:1.0003.0004.0002.0001.00081.000256.00016.000FLAG TO CONTROL WHETHER TO PRINT DIFF-CHART:输出数据 文件:output2.datNn(x)= 38.500000000000000Fonvard difference diagram:1.000000000 16.0000000015.0000000081.0000000065.0000000050.00000000256.0000000175.0000000110.000000060.000
5、00000D)结果分析本算例用四个节点的Newton向前插值计算公式对四次函数进行插值,计算误差为: 绝对误差:|38.500000000000000-2.54|=|38.5-39.0625|=0.5625;相对误差: 05625/390625=144%;3)n次Newton向后插值计算公式;A)流程图(与n次Nelon向前插值计算时类似)E)程序(程序三)C)计算实例输入数据文彳牛:input3.datKNOWN NODES NUMBER AND NODE X WITH Y(X)WANT TO EE KNOWN:42.5NODES XI AND YI WHICH ARE ALREADY KN
6、OWN:1.0003.0004.0002.0001.00027.00064.0008.000FLAG TO CONTROL WHETHER TO PRINT DIFF-CHART:输出数据文件:output3.datNu(x)= 15.625000000000000Eackward difference diagiaiu:64.0000000027.00000000-37.000000008.000000000 19.0000000018.000000001.000000000-7,00000000012.00000000-6.000000000D)结果分析本算例用四个节点的Newton向后插
7、值计算公式对三次函数进行插值,计算结果精确。二. 齐次线性方程组的直接法求解编制解心=1)的通用子程序。1)列主元消去法;流程图(图4、5)100.0.0.37.4.0.46. 400.0.110.038.00. 200.0.40.55.73.0.0.100.61.0.20.19.-0.-0. 100 0.075.0.0.0. 200.RIGHT VECTOR IS:20.11.23.63.72.91.程序(程序四、五)计算实例 输入数据文件input.dm COEFFICIENTS MATRIX IS:输出数据文件output.datAnswer to the simutaiieous li
8、neai equations is:-4.312691791318356E-001-6.207237146208434E-0028.578492048870718E-0011.679627521841597E-001VERIFY DATA.Difference between the Original Vector and Matrix*P:3.552713678800501E-0157.105427357601002E-0151.421085471520200E-0141.065814103640150E-0141.150000000000000E-0014.351687505777960E
9、-0010.000000000000000E+0000.000000000000000E+000结果分析从output.dat中的校验数据(VERIFYDATA)可见,方程组的求解精度可以达到1.0*10-14 (校验数据=原来右 端向量原来系数矩阵*求解结果)。2)实现矩阵三角分解的Doolittle及Cholesky三角分解方法及用此方法解Ax=b的过程; Doolittle三角分解方法A)流程图(图6)E)程序(程序四、六)C)计算实例输入数据文件mput.dat:(与上面列主元消去法时相同)输出数据文件 output.dat:Answer to the simutaiieous lin
10、eai equations is:-4.312691791318356E-001-6.207237146208434E-0028.578492048870718E-0011.679627521841597E-001VERIFY DATA.Difference between the Original Vector and Matrix*P:3.552713678800501E-0157.105427357601002E-0151.421085471520200E-0141.065814103640150E-014D)结果分析1.150000000000000E-0014.35168750577
11、7960E-0010.000000000000000E+0000.000000000000000E+000从output.dat中的校验数据(VERIFYDATA)町见,方程组的求解精度可以达到1.0*1015. 与上面列主元消去法时的计算结呆比较,可见有相同的很高的求解精度。11348 3.83261.16513.4017_ 9.5342_0.5301 1.78752.53301.54356.39413.4129 4.9317&76431.314218.42311.2371 4.9998 10.6721 0.014716.9237Choleskv三角分解方法(见下面4)3)用列主元消去法程序
12、解方程组并比较计算结果精度(准确解为Xi=X2=X3=X4=l) 输入数据文件mput.dat:COEFFICIENTS MATRIX IS:1.1348 0.53013.83261.78571.16512.53303.40171.54353.41291.23714.9317 4.99988.7643 10.67211.3142 0.0147RIGHT VECTOR IS:输出 数据文件 output.dat:Answer to the simutaiieous lineai equations is:9.997246338638249E-0019.971273542063148E-0011.
13、0013745262416351.002328461426957VERIFY DATA.Difference between the Original Vector and Matrix*P:1.332267629550188E-0156.661338147750939E-0161.776356839400251E-0152.726985304235541E-015结果分析从output.dat中的校验数据(VERIFYDATA)町见,方程组的求解精度可以达到1.0*1015.4)用平方根法解线性方程组_ 4SYM12.280-2.45.4416.928245.2122.95735.87.45
14、19.6634.50.945A)流程图(与Doolittle三角分解类似)B)程序(程序四、七(LDL、八(LL7)C)计算实例输入数据文件input.datCOEFFICIENTS MATRIX IS:4.2.423.2.45.4445.82.45.217.453.5.87.4519.66RIGHT VECTOR IS:12.28016.92822.95750.945输出数据文件output.datAnswer to the simutaiieous lineai equations is:1.200000000000000 -7.999999999999994E-0011.7000000000000002.000000000000000VERIFY DATA.Difference between t