东北石油大学计算方法上机实验答案(0页).doc

东北石油大学计算方法上机实验答案(0页).doc

  1. 1、本文档共8页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
东北石油大学计算方法上机实验答案(0页)

PAGE  PAGE 8 实验一 1. Private Function f(x!) f=x^3-2*x^2-4*x-7 End Function Private Sub form_click() Dim a!, b!, x!, c! a = 3: b = 4 Do While Abs(b - a) 0.00001 c = (a + b) / 2 If f(c) = 0 Then Exit Do Else If f(a) * f(c) 0 Then b = c Else a = c End If End If Loop Print c End Sub 1.(对1题进行修改后,要求输入隔根区间的上下界就能求出根的程序) Private Function f(x!) f = x ^ 3 - 2 * x ^ 2 - 4 * x - 7 End Function Private Function g(a!, b!) Dim y! Do While Abs(b - a) 0.00001 y = (a + b) / 2 If f(y) = 0 Then Exit Do Else If f(a) * f(y) 0 Then b = y Else a = y End If End If Loop g = y End Function Private Sub form_click() Dim a!, b! a = InputBox(输入隔根区间上界) b = InputBox(输入隔根区间下界) c = g(a, b) Print c End Sub 2. Private Function f(x!) f = x ^ 4 - 5 * x ^ 2 + x + 2 End Function Private Sub form_click() Dim a!, b!, c!, h!, x!, i%, j%, p(0 To 4) As Single, q(0 To 4) As Single a = -6: b = 6: h = 0.3 x = a i = 0 For j = 0 To 100 If f(x) * f(x + h) = 0 Then p(i) = x q(i) = x + h Print [; p(i); ,; q(i); ] i = i + 1 End If j = j + 1 x = x + h Next Print 实根分别为: For i = 0 To 3 a = p(i) b = q(i) Do While Abs(b - a) 0.00001 c = (a + b) / 2 If f(c) = 0 Then Exit Do Else If f(a) * f(c) 0 Then b = c Else a = c End If End If Loop Print root=; c Next End Sub (h 取值 使得划分的隔根区间避开根所在得区间上下界) 3. Private Sub form_click() Dim a(0 To 20) As Single, y As Single, x As Single Dim i As Integer, n As Integer n = InputBox(输入多项式的次数) For i = 0 To n a(i) = InputBox(输入a( Str(i) )) Next i x = InputBox(输入x) y = a(n) For i = 1 To n y = y * x + a(n - i) Next i Print y End Sub 实验二 1.(1) Private Sub form_click() Dim x0 As Single, x1 As Single Dim M As Integer x1 = 2: M = 5: k = 1 Do x0 = x1 x1 = x0 - (x0 ^ 3 - x0 ^ 2 - 2 * x0 - 3) / (3 * x0 ^ 2 - 2 * x0 - 2) k = k + 1 Loop While k M And Abs(x1 - x0) 0.00001 Print x1 End Sub (2) Private Sub form_click() Dim x0 As Single, x1 As Single Dim M As Integer x1 = 1:

文档评论(0)

2017ll + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档