数值计算 第六章
- 格式:docx
- 大小:51.65 KB
- 文档页数:7
第一章测试1.数值计算方法研究的误差有()A:截断误差;B:观测误差;C: 模型误差;D:舍入误差.答案:AD2.A:只有模型误差、截断误差与观测误差。
B: 只有舍入误差、截断误差与观测误差;C:只有模型误差、观测误差与舍入误差;D:只有模型误差、截断误差与舍入误差;答案:C3.A:4位B:5位C:3位D:2位答案:A4.对于下列表达式,用浮点数运算,精度较高是A:B:C:D:答案:A5.A:B:C:D:答案:B第二章测试1.A:0.5000B:0.6250C:0.5625D:0.6875答案:C2.A:B:C:D:答案:CD3.关于Steffensen(斯蒂芬森)迭代方法,下列命题中正确的是:A:Steffensen迭代法使得收敛的迭代格式加速收敛,发散的迭代格式更快发散。
B:Steffensen迭代法使得某些发散的迭代格式变为收敛。
C:Steffensen迭代法使得任何收敛的迭代格式加速收敛。
D:Steffensen迭代法使得某些收敛的迭代格式加速收敛。
答案:BD4.关于Newton迭代法,下列命题中正确的是:A:求解任一方程的Newton迭代法都是2阶收敛的。
B:Newton迭代格式若收敛,则一定是超线性收敛的。
C:D:Newton迭代格式可能收敛也可能发散。
答案:CD5.A:6B:3C:5D:4答案:A第三章测试1.A:若求解失败,则说明矩阵A奇异。
B:算法的计算量与近似成正比。
C:若A的对角线元素的绝对值都大于1,则求解结果的精度一定较高。
D:只要A非奇异,则求解结果的精度一定较高。
答案:B2.列主元Gauss消去法与Gauss顺序消元法相比,优点是:A:提高了稳定性,减少了误差的影响。
B:方程组的系数矩阵奇异时也可以求解。
C:能求出方程组的精确解。
D:减少了计算量。
答案:A3.A:平方根法与Gauss列主元消去法相比,提高了稳定性,但增加了计算量。
B:只要是对称正定矩阵,就可用平方根法求解。
《计算方法》教案课程名称:计算方法适用专业:医学信息技术适用年级:二年级任课教师:***编写时间:2011年 8月新疆医科大学工程学院张利萍教案目录《计算方法》教学大纲 (4)一、课程的性质与任务 (4)二、课程的教学内容、基本要求及学时分配 (4)三、课程改革与特色 (5)四、推荐教材及参考书 (5)《计算方法》教学日历..................................... 错误!未定义书签。
第一章绪论 .. (6)第1讲绪论有效数字 (6)第2讲误差………………………………………………………………………………第二章线性方程组的直接法 (14)第3讲直接法、高斯消去法 (14)第4讲高斯列主元消去法 (22)第5讲平方根法、追赶法 (29)第三章插值法与最小二乘法 (31)第6讲机械求积、插值型求积公式 (32)第7讲牛顿柯特斯公式、复化求积公式 (37)第8讲高斯公式、数值微分 (42)第9讲第10讲第12讲第四章数值积分与数值微分 (48)第11讲欧拉公式、改进的欧拉公式 (48)第12讲龙格库塔方法、亚当姆斯方法 (52)第13讲收敛性与稳定性、方程组与高阶方程 (56)第14讲第15讲第五章微分常微分方程的差分方法 (59)第16讲迭代收敛性与迭代加速 (60)第17讲牛顿法、弦截法 (64)第18讲第19讲第20讲第六章线性方程组的迭代法 (67)第21讲迭代公式的建立 (68)第22讲第23讲第24讲向量范数、迭代收敛性 (71)第25讲《计算方法》教学大纲课程名称:计算方法/Computer Numerical Analysis B学时/学分:54/4先修课程:高等数学、线性代数、高级语言程序设计(如:Matlab语言)适用专业:计算机科学与技术、信息管理与信息系统开课学院(部)、系(教研室):医学工程技术学院、医学信息技术专业一、课程的性质与任务计算方法是一门专业必修课。
import xiaodeng.method.Matrix;/*** @author邓仕军* @time 2012-06-04* @version0.1* @function:Gauss-Seidel迭代法解线性方程组*/class Program6_1 {Matrix coefficientMatrix;// 系数矩阵Matrix constantMatrix;// 常数矩阵double[] result;// 结果集double precious = 10E-5;int size = 0;// result也即结果集的长度public Program6_1(Matrix coefficientMatrix, Matrix constantMatrix, double precious) {this.coefficientMatrix = coefficientMatrix;this.constantMatrix = constantMatrix;this.precious = precious;this.size = coefficientMatrix.getNumColumns();result = newdouble[size];}// 返回result中的最大值double maxValueOfDiffer(double[] d1, double[] d2) {double max = 0d;for (int i = 0; i<this.size; i++) {double temp = Math.abs(d1[i] - d2[i]);if (i == 0 || max < temp) {max = temp;}}return max;}// 根据当前的result,计算一次,得到新的resultpublicdouble[] calculate() {for (int i = 1; i<= constantMatrix.getNumRows(); i++) {double sum = constantMatrix.getElementAt(i, 1);for (int j = 1; j <= constantMatrix.getNumRows(); j++) { if (j != i)sum -= coefficientMatrix.getElementAt(i, j) * result[j - 1];}// for-2result[i - 1] = sum / coefficientMatrix.getElementAt(i, i);}// for-1return result.clone();//}// calculate// 根据精度,调用calculate,得到在精度范围内的结果集publicvoid function() {double[] temp1, temp2;// 虽然java会自动初始化result为0,但是为了程序的可读性、可移植性、扩展性,还是在这里手动初始化一下for (int i = 0; i<this.size; i++) {result[i] = 0d;}temp1 = calculate();temp2 = calculate();while (maxValueOfDiffer(temp1, temp2) >this.precious) { temp1 = temp2;temp2 = calculate();}// while}// functiondouble getPrecious() {return precious;}void setPrecious(double precious) {this.precious = precious;}int getSize() {return size;}void setSize(int size) {this.size = size;}Matrix getCoefficientMatrix() {return coefficientMatrix;}Matrix getConstantMatrix() {return constantMatrix;}double[] getResult() {return result.clone();}}import xiaodeng.method.Matrix;publicclass TestProgram6_1 {publicstaticvoid main(String[] args) {Program6_1 p6_1 = new Program6_1(new Matrix(3, 3, newdouble[][] {{ 8, -3, 2 }, { 4, 11, -1 }, { 2, 1, 4 } }), new Matrix(3, 1,newdouble[][] { { 20 }, { 33 }, { 12 } }), 10E-5);p6_1.function();// 解方程System.out.println("方程组为:");for(int i = 1; i<= p6_1.getCoefficientMatrix().getNumRows(); i++) {for (int j = 1; j <=p6_1.getCoefficientMatrix().getNumColumns(); j++)if (j != p6_1.getCoefficientMatrix().getNumColumns())System.out.print(p6_1.getCoefficientMatrix().getElementAt(i, j)+ "x" + j + " + ");else {System.out.print(p6_1.getCoefficientMatrix().getElementAt(i, j)+ "x"+ j+ " = "+ p6_1.getConstantMatrix().getElementAt(i, 1));}System.out.println();}System.out.println("解得:");for (int i = 0; i< p6_1.getSize(); i++) {System.out.println("x"+ (i + 1) + "="+ p6_1.getResult()[i]);}}}import ng.reflect.InvocationTargetException;import ng.reflect.Method;/*** @author邓仕军* @time 2012-06-07* @version 0.2* Newton迭代法*/class Program6_2 {Method f;double x0;double precious;Derivative derivaFx;// 导数public Program6_2(Method f, double x0, double precious) { this.f = f;this.x0 = x0;this.precious = precious;derivaFx = new Derivative(this, this.f);derivaFx.setPrecision(this.precious);}publicdouble function() {double Xk = 0d, Xk1 = 0d;try {Xk = this.x0 - (Double) this.f.invoke(null, this.x0)/ this.derivaFx.getDerivative(this.x0);Xk1 = Xk - (Double) this.f.invoke(null, Xk)/ this.derivaFx.getDerivative(Xk);while (Math.abs(Xk - Xk1) >this.precious) {Xk = Xk1;Xk1 = Xk - (Double) this.f.invoke(null, Xk)/ this.derivaFx.getDerivative(Xk);}// while} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {e.printStackTrace();}return (Xk + Xk1) / 2;}// functionpublicdouble getX0() {return x0;}publicvoid setX0(double x0) {this.x0 = x0;}publicdouble getPrecious() {return precious;}publicvoid setPrecious(double precious) {this.precious = precious;}}/***@author邓仕军*@version 0.1*@time 2012-05-03* Derivative:求一个函数的导数,运用反射机制*/class Derivative {Method method;Object obj;double Dx = 1;// 增量△Xdouble precision = 10E-10;// 精度public Derivative(Object obj, Method f) {this.method = f;this.obj = obj;}strictfpdouble getDerivative(double x) {double deriva1 = 0d, deriva2 = 0d;boolean flag = true;double dx = this.Dx;try {deriva1 = ((Double) this.method.invoke(obj, x + dx) - (Double) method.invoke(obj, x)) / dx;dx /= 2;while (flag) {deriva1 = ((Double) this.method.invoke(obj, x + dx) - (Double) method.invoke(obj, x)) / dx;if (Math.abs(deriva1 - deriva2) <this.precision)flag = false;else {deriva2 = deriva1;dx /= 2;}}// while} catch (IllegalAccessException | IllegalArgumentException| InvocationTargetException e) {e.printStackTrace();}return (deriva1 + deriva2) / 2;}// getDerivativepublicdouble getDx() {return Dx;}publicvoid setDx(double dx) {Dx = dx;}publicdouble getPrecision() {return precision;}publicvoid setPrecision(double precision) {this.precision = precision;}}publicclass TestProgram6_2 {staticdouble fX(double x) {return Math.pow(Math.E, 5 * x) - Math.sin(x) + Math.pow(x, 3) - 20;}publicstaticvoid main(String[] args) {double x0 = 1;double precious = 10E-8;try {Program6_2 p6_2 = new Program6_2(TestProgram6_2.class.getDeclaredMethod("fX", double.class),x0, precious);System.out.printf("方程为:e^(5x)-sinx+x^3-20=0 ,精度 ");System.out.println(precious);System.out.println("取 x0=" + x0 + ",解得x=" +p6_2.function());--x0;p6_2.setX0(x0);System.out.println("取 x0=" + x0 + ",解得x=" +p6_2.function());} catch (NoSuchMethodException | SecurityException e) {e.printStackTrace();}}}。