vB编写线性方程.docx

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

实验一:线性方程组解算一、实验目的与要求⒈初步掌握线性方程组的算法;⒉初步掌握线性方程组在计算机上实现方法。二、实验安排⒈实验共需用2学时。⒉实验每个小组1人,用VB等语言在计算机上完成程序代码的编写,并调试通过,然后用算例印证程序的正确性。三、实验步骤及要点⒈在课余时间,提前准备线性方程组解算程序代码;⒉上机时写入代码,并调试运行;⒊用算例进行印证。四、实验原理利用高斯选主元消去法:五、程序代码Public Function guass(n As Integer, a() As Single, b() As Single, x() As Single)Dim iAs Integer, j As Integer, k As IntegerDim amax As Single, imax As Integer, s As SingleDim m As Single, t As Single, mm As SingleFor j = 1 To (n - 1)amax = Abs(a(j, j))imax = jFor i = j + 1 To nIf (Abs(a(i, j)) amax) Thenamax = Abs(a(i, j))imax = iEnd IfNext iIf (imax j) ThenFor k = j To nt = a(imax, k)a(imax, k) = a(j, k)a(j, k) = tNext kbmax = b(imax)b(imax) = b(j)b(j) = bmaxEnd IfFor i = j + 1 To nt = 1# / a(j, j)t = t * a(i, j)For k = j To na(i, k) = a(i, k) - a(j, k) * tNext kb(i) = b(i) - b(j) * tNext iNext jFor i = 1 To nm = 0mm = 0For j = iTo nm = m + a(i, j)mm = mm - a(i, j)Next jIf (m 0.000001 And mm 0.000001) ThenMsgBox 无穷多解EndEnd IfNext ix(n) = b(n) / a(n, n)For i = n - 1 To 1 Step -1m = 0For j = n Toi + 1 Step -1m = m + a(i, j) * x(j)Next jx(i) = (b(i) - m) / a(i, i)Next iEnd FunctionPrivate Sub Command1_Click()Dim s() As Single, x() As SingleDim a() As Single, b() As SingleDim iAs Integer, j As Integer, k As IntegerDim amax As Single, imax As IntegerDim m As Single, n As Integer, c As SingleDim p As StringIf Not IsNumeric(Text1.Text) ThenMsgBox 请输入数字, , 警告:Else:again:n = Val(Text1.Text)ReDima(n, n) As SingleReDimb(n) As Single, x(n) As SingleFor i = 1 To nFor j = 1 To na(i, j) = Val(InputBox(系数矩阵a ( i j )数值:, 输入框))Picture1.Print a(i, j); vbTab; ;Next jPicture1.Print Chr(13)Next iFor i = 1 To nb(i) = Val(InputBox(列向量b ( i )数值:, 输入框))Picture2.Print b(i); ;Picture2.Print Chr(13)Next iCall guass(n, a, b, x)For j = 1 To np = x( Str(j) )= Format(Str(x(j)), #0.0000)Picture3.Print p; ;Picture3.Print Chr(13)Next jOn Error GoTo again:End IfEnd SubPrivate Sub Command3_Click()Picture1.ClsPicture2.ClsPicture3.ClsText1.Text = End SubPrivate Sub Command4_Click()EndEnd SubPri

文档评论(0)

159****0071 + 关注
实名认证
内容提供者

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

1亿VIP精品文档

相关文档