计算方法与实习上机实验报告

上传人:ali****an 文档编号:120451278 上传时间:2020-02-06 格式:PDF 页数:35 大小:392.94KB
返回 下载 相关 举报
计算方法与实习上机实验报告_第1页
第1页 / 共35页
计算方法与实习上机实验报告_第2页
第2页 / 共35页
计算方法与实习上机实验报告_第3页
第3页 / 共35页
计算方法与实习上机实验报告_第4页
第4页 / 共35页
计算方法与实习上机实验报告_第5页
第5页 / 共35页
点击查看更多>>
资源描述

《计算方法与实习上机实验报告》由会员分享,可在线阅读,更多相关《计算方法与实习上机实验报告(35页珍藏版)》请在金锄头文库上搜索。

1、 东 南 大 学 计算方法与实习 上机实验报告 学号 02607113 姓名 周金波 指导老师 李翠平 实验时间 2009 12 26 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 2 目录 1 1 舍入误差与数值稳定性舍入误差与数值稳定性 3 1 1舍入误差与数值稳定性 3 1 2 实习题 3 2 2 方程求根方程求根 9 2 1 二分法 9 2 2 牛顿迭代法 11 3 3 线性方程组数值解法线性方程组数值解法 17 3 1 列主元高斯消去法 17 3 2 追赶法 19 3 3 迭代法 21 3 3 1 雅可比迭代法 21 3 3 2 高斯 赛德尔迭代法

2、 24 4 4 插值法插值法 26 4 1 拉格朗日插值多项式 26 4 2 牛顿插值多项式 28 5 5 曲线拟合曲线拟合 29 5 1 最小二乘法 29 6 6 数值积分数值积分 33 6 1 复化梯形公式与复化辛卜生公式的自适应算法 33 6 1 1 复化辛卜生公式 33 6 1 2 自适应梯形公式 34 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 3 实验一实验一 舍入误差与数值稳定性舍入误差与数值稳定性 实习题 1 用 2 种不同的顺序计算 n 1 644834 分析其误 差的变化 程序一 顺序 include include include v

3、oid main double y1 1 y2 int n 1 cout y 1 setw 8 y1 while 1 y2 y1 1 pow n 1 2 cout y n 1 setw 8 9999 break y1 y2 n if n 3 0 cout n 运行结果 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 4 程序二 倒序 include include include void main double y1 y2 1 644834 int n 10000 cout y 10000 setw 8 y2 while 1 y1 y2 1 pow n 2

4、cout y n 1 setw 8 y2 if n 2 break y2 y1 n if n 3 0 cout n 运行结果 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 5 实习题 2 设S 已知其精确值为 1 编制按从大到小的顺序计算S 的程序 2 编制按从小到大的顺序计算S 的程序 3 按 2 种顺序分别计算S S S 并指出 有效位数 1 程序 include include include void main double y1 y2 b 1 3 0 int n N cout N n N y2 1 5 1 N 1 N 1 2 cout y N se

5、tw 15 y2 while 1 y1 y2 1 pow n 2 1 cout y n 1 setw 15 y1 if n 3 break y2 y1 n if n 3 0 cout n cout endl 其精确值为 b endl cout 误差大约为 fabs y1 b endl 2 程序 include include include void main 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 6 double y1 0 33333333 y2 b int n 2 N cout N b 1 5 1 N 1 N 1 2 cout y 2 setw

6、8 y2 while 1 y2 y1 1 pow n 1 2 1 cout y n 1 setw 8 N 1 break y1 y2 n if n 3 0 cout n cout 其精确值为 b endl cout 误差大约为 fabs y2 b endl 3 N 1000 顺序 运行结果 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 7 4 N 1000 倒序 运行结果 N 10000 顺序 运行结果 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 8 N 10000 倒序 运行结果 N 30000 顺序 运行结果 计算方

7、法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 9 N 30000 倒序 运行结果 分析体会 按不同的顺序编制程序 并进行运算 极有可能得到两个 不同精度的结果 因为有可能因为顺序的颠倒而使得误差放大 实验二实验二 方程求根方程求根 实习题 1 求方程 f x x x 3x 3 0在 1 5 附近的根 程序 include include include define eps 5e 6 define delta 1e 6 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 10 float Bisection float a float

8、 b float f float float c fc fa f a fb f b int n 1 cout setw 10 二分次数 setw 16 c setw 16 fc 0 cout 不能用二分法求解 break c a b 2 fc f c if fabs fc delta break else if fa fc 0 b c fb fc else a c fa fc if b a eps break cout setw 10 n setw 16 c setw 16 fc n return c float f float x return x x x x x 3 x 3 void ma

9、in float a 1 b 2 float x x Bisection a b f cout 方程的根为 x n 运行结果 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 11 实习题 2 用牛顿法求下列方程的根 1 x e 0 2 lgx x 2 0 程序一 include include include define N 100 define eps 1e 6 define eta 1e 8 float Newton float f float float ff float float x0 float x1 d int k 0 do x1 x0 f x

10、0 ff x0 if k N fabs ff x1 eps cout Newton 迭代发散 endl 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 12 break d fabs x1 1 x1 x0 x1 x0 x1 x0 x1 cout setw 12 x k setw 10 x0 if k 3 0 cout eps return x0 float f float x return x x exp x float ff float x return 2 0 x x exp x void main float x0 xt cout x0 xt Newto

11、n f ff x0 cout endl cout 方程的根为 xt n 运行结果 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 13 程序二 include include include define N 100 define eps 1e 6 define eta 1e 8 float Newton float f float float ff float float x0 float x1 d int k 0 do x1 x0 f x0 ff x0 if k N fabs ff x1 eps cout Newton 迭代发散 endl break d

12、fabs x1 1 x1 x0 x1 x0 x1 x0 x1 cout setw 12 x k setw 10 x0 if k 3 0 cout eps return x0 float f float x return log10 x x 2 float ff float x return log10 exp 1 x 1 void main float x0 xt cout x0 xt Newton f ff x0 cout endl cout 方程的根为 xt n 运行结果 实习题 3 编写一个割线法的程序 求解上述各方程 程序一 include include include define

13、 N 10000 define eps 1e 6 define eta 1e 8 float Newton float f float float x1 float x0 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 15 float x2 d int k 0 do x2 x1 f x1 x1 x0 f x1 f x0 if k N fabs f x1 f x0 x1 x0 eps cout endl Newton 迭代发散 endl break d fabs x2 1 x2 x1 x2 x1 x2 x0 x1 x1 x2 cout setw 12 x k

14、setw 10 x2 if k 3 0 cout eps return x2 float f float x return x x exp x void main float x0 x1 xt cout x0 cout x1 xt Newton f x1 x0 cout endl cout 方程的根为 xt n 运行结果 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 16 程序二 include include include define N 10000 define eps 1e 6 define eta 1e 8 float Newton float

15、f float float x1 float x0 float x2 d int k 0 do x2 x1 f x1 x1 x0 f x1 f x0 if k N fabs f x1 f x0 x1 x0 eps cout endl Newton 迭代发散 endl break d fabs x2 1 x2 x1 x2 x1 x2 x0 x1 x1 x2 cout setw 12 x k setw 10 x2 if k 3 0 cout eps return x2 float f float x return log10 x x 2 void main 计算方法 论文报告 PDF 文件使用 p

16、dfFactory Pro 试用版本创建 17 float x0 x1 xt cout x0 cout x1 xt Newton f x1 x0 cout endl cout 方程的根为 xt n 运行结果 分析体会 由上面的实习题得出的结果可以看出 求解同一个方程的近似解 在最终结果相同的情况下 割线法优于牛顿法优于二分法 实验三实验三 线性方程组数值解法线性方程组数值解法 实习题 1 用列主元消去法解方程组 x x 3x 4 2x x x x 1 3x x x 3x 3 x 2x 3x x 4 程序 include include void main 计算方法 论文报告 PDF 文件使用 pdfFactory Pro 试用版本创建 18 void ColPivot float int float int i float x 4 float c 4 5 1 1 0 3 4 2 1 1 1 1 3 1 1 3 3 1 2 3 1 4 ColPivot c 0 4 x for i 0 i 3 i cout x i x i endl void ColPivot float c int n

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 机械/制造/汽车 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号