| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 628 人关注过本帖
标题:[求助]高斯消主元法解线性方程组
只看楼主 加入收藏
桃源书生
Rank: 1
等 级:新手上路
帖 子:99
专家分:3
注 册:2006-7-3
结帖率:33.33%
收藏
 问题点数:0 回复次数:0 
[求助]高斯消主元法解线性方程组

我编了一个求有6个未知数的线性方程组的小程序,在对01.txt求解时可以得到正确的解,但是对02.txt求解时却得不到正确的解。请问应该如何修改程序?谢谢!
注:01.txt和02.txt为线性方程组的增广矩阵。
程序代码如下:

Private Sub Form_Load()
'***********读取数据文件*************
CommonDialog1.ShowOpen
Dim files As String, i As Integer, j As Integer, L() As Single
files = CommonDialog1.FileName
Dim inbuf As String
Open files For Input As #1 '打开文件
num = 0 'num为文件行数
Do While Not EOF(1) '获取文件行数
Line Input #1, inbuf
num = num + 1
Loop
Close #1
ReDim L(1 To num + 1, 1 To 7) '矩阵
Open files For Input As #1
For i = 1 To num '将数据赋值给数组L
For j = 1 To 7
Input #1, L(i, j)
Next j
Next i
Close #1
Open files For Input As #1
Close #1

Dim L1 As Single, L2 As Single, j1 As Integer, j2 As Integer, k1 As Integer, k2 As Integer
Dim x1 As Single, x2 As Single, x3 As Single, x4 As Single, x5 As Single, x6 As Single
For i = 1 To num - 1
For j1 = i + 1 To num
If L(j1, i) >= L(i, i) Then
For k1 = i To 7
L(num + 1, k1) = L(i, k1)
L(i, k1) = L(j1, k1)
L(j1, k1) = L(num + 1, k1)
Next k1
Else
End If
Next j1
L1 = L(i, i)
For j2 = i + 1 To num
L2 = L(j2, i)
For k2 = i To 7
L(i, k2) = L(i, k2) / L1
L(j2, k2) = L(j2, k2) - L(i, k2) * L2
Next k2
Next j2

Next i
x6 = L(6, 7) / L(6, 6)
x5 = L(5, 7) - x6 * L(5, 6)
x4 = L(4, 7) - x6 * L(4, 6) - x5 * L(4, 5)
x3 = L(3, 7) - x6 * L(3, 6) - x5 * L(3, 5) - x4 * L(3, 4)
x2 = L(2, 7) - x6 * L(2, 6) - x5 * L(2, 5) - x4 * L(2, 4) - x3 * L(2, 3)
x1 = L(1, 7) - x6 * L(1, 6) - x5 * L(1, 5) - x4 * L(1, 4) - x3 * L(1, 3) - x2 * L(1, 2)

Text1.Text = x1
Text2.Text = x2
Text3.Text = x3
Text4.Text = x4
Text5.Text = x5
Text6.Text = x6
Text7 = x1 + 2 * x2 + 3 * x3 + 4 * x4 + 5 * x5 + 6 * x6
End Sub

uSjsI4FP.rar (2.91 KB) [求助]高斯消主元法解线性方程组


[此贴子已经被作者于2007-6-5 13:26:30编辑过]

搜索更多相关主题的帖子: 高斯 线性方程 
2007-06-05 13:26
快速回复:[求助]高斯消主元法解线性方程组
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036381 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved