计算机在材料科学中的应用上机指导书1.doc
《计算机在材料科学中的应用上机指导书1.doc》由会员分享,可在线阅读,更多相关《计算机在材料科学中的应用上机指导书1.doc(25页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、计算机在材料科学中的应用上机指导书材料学院实验目录实验一 方程求根 (2学时)3实验二 线性方程组求解(2学时)6实验三 最小二乘法曲线拟合及回归分析数值计算 (4学时)10实验四 插值计算(2学时)15实验五 传热学计算机分析 (2学时)17实验六 相图热力学计算 (4学时)19实验七 互联网在材料科学中的应用 (2学时)21实验八 常用软件学习(2学时)23实验一 方程求根 2学时一、实验目的及任务要求1、实验目的:1)熟悉程序设计语言,了解简单的程序设计方法;2)熟悉迭代法求方程根及牛顿法求方程的算法设计;3)熟悉简单算法程序编写及调试方法。2、任务要求:1)熟悉机房环境;2)理解算法原
2、理及程序编译过程。二、实验操作过程1、熟悉VB(或C语言)编译软件界面VB语言是一种面向对象的高级程序设计语言,目前应用较多的是Visual Basic6.0版本。界面如图所示:属性代码窗口窗体2、熟悉算法1)二分法求方程根11 2)牛顿法求方程根3、程序设计1)例题分析:以二分迭代法求解方程x3-x-1=0在区间0,2中的根(精度为e=10-6)f(x)= x3-x-1。程序设计(VB):Private Sub cmdjisuan_Click()Dim x1 As Single, x2 As Single, x3 As Singlex1 = 0x2 = 2Dox3 = (x1 + x2) /
3、 2If (x1 * x1 * x1 - x1 - 1) * (x3 * x3 * x3 - x3 - 1) 0 Thenx1 = x3Elsex2 = x3End IfLoop Until Abs(x2 - x1) 0.00001x = x - F(x) / dF(x)n = n + 1If n 1000 Thentxtroot.Text = 迭代发散Exit SubEnd IfLooptxtroot.Text = xEnd SubPrivate Function F(x0 As Single) As SingleF = x0 * x0 * x0 + 4 * x0 * x0 - 10End
4、FunctionPrivate Function dF(x1 As Single) As SingledF = 3 * x1 * x1 + 8 * x1End Function实验二 线性方程组求解 2学时一、实验目的及任务要求1、实验目的:1)熟悉雅可比迭代法及其算法设计;2)熟悉追赶法解线性方程组及其算法设计;3)熟悉简单算法程序编写及调试方法。2、任务要求:1)熟悉线性方程组常用数值解法;2)理解算法原理及程序编译过程。二、实验操作过程1、雅可比迭代法算法设计线性方程组的矩阵表达式为AX=b,其一般形式为:Aijxj=bi (i=1,2, n j=1,2, n)将此式改写为迭代格式: (
5、i=1, 2, ., n)程序设计:计算例题:给定初始值 x(0)=0,0,0T选代求解为 x*=3,2,1T程序设计(VB):Option ExplicitOption Base 1Private a(3, 3) As Single, b(3) As Single, x(3) As Single, y(3) As SinglePrivate Sub cmdjisuan_Click()a(1, 1) = 8: a(1, 2) = -3: a(1, 3) = 2a(2, 1) = 4: a(2, 2) = 11: a(2, 3) = -1a(3, 1) = 6: a(3, 2) = 3: a(3
6、, 3) = 12b(1) = 20: b(2) = 33: b(3) = 36y(1) = txtx1.Text: y(2) = txtx2.Text: y(3) = txtx3.TextDim i As Integer, j As Integer, N As Single, M(3) As Single, t As SingleDoFor i = 1 To 3t = 0For j = 1 To 3If i j Thent = t + a(i, j) * y(j) End IfNext jx(i) = (b(i) - t) / a(i, i)Next iFor i = 1 To 3M(i)
7、= Abs(x(i) - y(i)NextN = M(1)For i = 2 To 3If N 0.00000001txtroot1.Text = x(1): txtroot2.Text = x(2): txtroot3.Text = x(3)End Sub2、追赶法解线性方程组三对角方程组的形式如下:追赶法程序框图:计算例题:VB程序:Option ExplicitOption Base 1Private Sub cmdjisuan_Click()Dim a(5) As Single, b(5) As Single, c(5) As Single, d(5) As Singlea(2) =
8、-1: a(3) = -1: a(4) = -1: a(5) = -1b(1) = 4: b(2) = 4: b(3) = 4: b(4) = 4: b(5) = 4c(1) = -1: c(2) = -1: c(3) = -1: c(4) = -1d(1) = 100: d(2) = 200: d(3) = 200: d(4) = 200: d(5) = 100Dim i As Integerd(1) = d(1) / b(1): c(1) = c(1) / b(1)Dim t As SingleFor i = 2 To 4t = b(i) - a(i) * c(i - 1)c(i) = c
9、(i) / td(i) = (d(i) - a(i) * d(i - 1) / tNextd(5) = (d(5) - a(5) * d(4) / (b(5) - a(5) * c(4)For i = 4 To 1 Step -1d(i) = d(i) - c(i) * d(i + 1)Nexttxtx1.Text = d(1): txtx2.Text = d(2): txtx3.Text = d(3): txtx4.Text = d(4): txtx5.Text = d(5)End SubPrivate Sub Command1_Click()txtx1.Text = : txtx2.Tex
10、t = : txtx3.Text = : txtx4.Text = : txtx5.Text = 界面设计:实验三 最小二乘法曲线拟合及回归分析数值计算 4学时一、实验目的及任务要求1、实验目的:1)熟悉最小二乘法曲线拟合算法设计;2)熟悉该算法程序编写及调试方法。2、任务要求:1)熟悉一元及多元线性回归数值解法;2)理解算法原理及程序编译过程。二、实验操作过程1、一元线性回归已知现场的一组实测数据如下:选用直线方程,其形式为:y=a+bx一元线性回归的计算步骤: 1)输入原始数据输入原始数据主要包括,实测点的个数n,n组实测点值xi及函数值yi。 2)循环求和计算计算x, y, x2, y2
11、, xy 3)构造正则方程组:a11=N a12=x b1=y a21=x a22=x2 b2=xy 4)求解二元一次线性方程组利用克拉姆法则计算: 程序设计:Option ExplicitOption Base 1Private Sub Command1_Click()Dim n As IntegerDim x(4) As Single, y(4) As Single, b(2) As Singlex(1) = 2: x(2) = 4: x(3) = 6: x(4) = 8: y(1) = 2: y(2) = 11: y(3) = 28: y(4) = 40Dim a(2, 2) As Si
12、nglea(1, 1) = 4Dim i As Integer, x1 As Single, x2 As Single, t(3) As SingleFor i = 1 To 4a(1, 2) = a(1, 2) + x(i)a(2, 2) = a(2, 2) + x(i) * x(i)b(1) = b(1) + y(i)b(2) = b(2) + x(i) * y(i)Nexta(2, 1) = a(1, 2)t(1) = a(1, 1) * a(2, 2) - a(1, 2) * a(2, 1)t(2) = b(1) * a(2, 2) - b(2) * a(1, 2)t(3) = a(1
13、, 1) * b(2) - a(2, 1) * b(1)x1 = t(2) / t(1): x2 = t(3) / t(1)txta.Text = x1: txtb.Text = x2End SubPrivate Sub Command2_Click()txta.Text = : txtb.Text = End Sub2、多元线性回归P17 例2分析:求y对x1, x2, x3的线性回归方程。表22 去碳量y与天然矿石和烧结矿石的加入量x1, x2 及熔化时间x3实测数据 n=49,此题是三元线性回归,其回归系数a1、a2、a3满足三元正规方程:l11a1+l12a2+l13a3=l1yl21
14、a1+l22a2+l23a3=l2yl31a1+l32a2+l33a3=l3yl11 = x12-(x1)2 l12=l21=x1x2-(x1)(x2) l13=l31=x1x3-(x1)(x3) l22=x22-(x2)2 l23=l32=x2x3-(x2)(x3) l33=x32-(x3)2l1y=x1y-(x1)(y) l2y=x2y-(x2)(y) l3y=x3y-(x3)(y)计算步骤:1)输入数据:N49,x1i, x2i, x3i, yi (i=1,2, , 49)2) 计算:x12、x22、x32、x1、x2、x3、x1x2、x2x3、x1x3、x1y、x2y、x3y、y3)计
15、算线性方程组系数lij并解线性方程组4)计算a0,求出三元线性回归方程式。程序设计(VB):Option ExplicitOption Base 1Private Sub cmdjisuan_Click()Dim x1(49) As Double, x2(49) As Double, x3(49) As Double, y(49) As Doublex1(1) = 2: x1(2) = 7: x1(3) = 5: x1(4) = 12: x1(5) = 1x1(6) = 3: x1(7) = 3: x1(8) = 6: x1(9) = 7: x1(10) = 0x1(11) = 3: x1(1
16、2) = 0: x1(13) = 8: x1(14) = 6: x1(15) = 0x1(16) = 3: x1(17) = 7: x1(18) = 16: x1(19) = 6: x1(20) = 0x1(21) = 9: x1(22) = 4: x1(23) = 0: x1(24) = 9: x1(25) = 2x1(26) = 9: x1(27) = 12: x1(28) = 6: x1(29) = 12: x1(30) = 0x1(31) = 5: x1(32) = 4: x1(33) = 0: x1(34) = 6: x1(35) = 4x1(36) = 10: x1(37) = 4
17、: x1(38) = 5: x1(39) = 9: x1(40) = 6x1(41) = 5: x1(42) = 5: x1(43) = 8: x1(44) = 2: x1(45) = 7x1(46) = 4: x1(47) = 10: x1(48) = 3: x1(49) = 4x2(1) = 18: x2(2) = 9: x2(3) = 14: x2(4) = 3: x2(5) = 20x2(6) = 12: x2(7) = 17: x2(8) = 5: x2(9) = 8: x2(10) = 23x2(11) = 16: x2(12) = 18: x2(13) = 4: x2(14) =
18、 14: x2(15) = 21x2(16) = 14: x2(17) = 12: x2(18) = 0: x2(19) = 16: x2(20) = 15x2(21) = 0: x2(22) = 6: x2(23) = 17: x2(24) = 0: x2(25) = 16x2(26) = 6: x2(27) = 5: x2(28) = 13: x2(29) = 7: x2(30) = 24x2(31) = 12: x2(32) = 15: x2(33) = 20: x2(34) = 16: x2(35) = 17x2(36) = 4: x2(37) = 14: x2(38) = 13: x
19、2(39) = 8: x2(40) = 13x2(41) = 8: x2(42) = 11: x2(43) = 6: x2(44) = 13: x2(45) = 8x2(46) = 10: x2(47) = 5: x2(48) = 17: x2(49) = 15x3(1) = 50: x3(2) = 40: x3(3) = 46: x3(4) = 43: x3(5) = 64x3(6) = 40: x3(7) = 64: x3(8) = 39: x3(9) = 37: x3(10) = 55x3(11) = 60: x3(12) = 49: x3(13) = 50: x3(14) = 51:
20、x3(15) = 51x3(16) = 51: x3(17) = 56: x3(18) = 48: x3(19) = 45: x3(20) = 52x3(21) = 40: x3(22) = 32: x3(23) = 47: x3(24) = 44: x3(25) = 39x3(26) = 39: x3(27) = 51: x3(28) = 41: x3(29) = 47: x3(30) = 61x3(31) = 37: x3(32) = 49: x3(33) = 45: x3(34) = 42: x3(35) = 48x3(36) = 48: x3(37) = 36: x3(38) = 36
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 材料科学 中的 应用 上机 指导书
限制150内