首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求解五元一次方程的C#算法解决办法

2012-01-13 
求解五元一次方程的C#算法在网上搜了下,说关于求解五元一次方程的C#算法很多,源代码也很多,但我却找不到。

求解五元一次方程的C#算法
在网上搜了下,说关于求解五元一次方程的C#算法很多,源代码也很多,但我却找不到。那位给个C#的源代码,在线等,谢谢。在最好是用高斯消元法。

[解决办法]
是方程组吧?
应该用矩阵来处理,大学的线性代数有讲。
另外大学学过《计算方法》也有解方程组的算法流程图和源码
[解决办法]
http://www.codeproject.com/csharp/matrix.asp
[解决办法]
回去翻下 <线性代数> 就知道了
[解决办法]
sub gaussj(a(), n, b())
'高斯消元法。
dim ipiv(50), indxr(50), indxc(50)
for j = 1 to n
ipiv(j) = 0
next
for i = 1 to n
big = 0
for j = 1 to n
if ipiv(j) <> 1 then
for k = 1 to n
if ipiv(k) = 0 then
if abs(a(j, k)) > = big then
big = abs(a(j, k))
irow = j
icol = k
end if
elseif ipiv(k) > 1 then
havaResult = false
exit sub
end if
next
end if
next
ipiv(icol) = ipiv(icol) + 1
if irow <> icol then
for l = 1 to n
dum = a(irow, l)
a(irow, l) = a(icol, l)
a(icol, l) = dum
next
dum = b(irow)
b(irow) = b(icol)
b(icol) = dum
end if
indxr(i) = irow
indxc(i) = icol
if a(icol, icol) = 0 then
havaResult = false
exit sub
end if
pivinv = 1 / a(icol, icol)
a(icol, icol) = 1
for l = 1 to n
a(icol, l) = a(icol, l) * pivinv
next
b(icol) = b(icol) * pivinv
for ll = 1 to n
if ll <> icol then
dum = a(ll, icol)
a(ll, icol) = 0
for l = 1 to n
a(ll, l) = a(ll, l) - a(icol, l) * dum
next
b(ll) = b(ll) - b(icol) * dum
end if
next
next
for l = n to 1 step -1
if indxr(l) <> indxc(l) then
for k = 1 to n
dum = a(k, indxr(l))
a(k, indxr(l)) = a(k, indxc(l))
a(k, indxc(l)) = dum
next
end if
next
end sub
[解决办法]
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>


float *GauseSeidel(float *c,int n)
{
int i,j,k,t;
float *x,p;
x=(float *)malloc(n*sizeof(float));
for(i=0;i <=n-2;i++)
{
k=i;
for(j=i+1;j <=n-1;j++)
if(fabs(*(c+j*(n+1)+i))> (fabs(*(c+k*(n+1)+i))))k=j;
if(k!=i)
for(j=i;j <=n;j++)
{
p=*(c+i*(n+1)+j);
*(c+i*(n+1)+j)=*(c+k*(n+1)+j);
*(c+k*(n+1)+j)=p;
}
for(j=i+1;j <=n-1;j++)
{
p=(*(c+j*(n+1)+i))/(*(c+i*(n+1)+i));
for(t=i;t <=n;t++)
*(c+j*(n+1)+t)-=p*(*(c+i*(n+1)+t));
}
}
for(i=n-1;i> =0;i--)
{
for(j=n-1;j> =i+1;j--)
(*(c+i*(n+1)+n))-=x[j]*(*(c+i*(n+1)+j));
x[i]=*(c+i*(n+1)+n)/(*(c+i*(n+1)+i));


}
return x;

}
void main()
{
float *x;
int i;
float c[10][11]={ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 55,
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 109,
1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 161,
1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 210,
1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 255,
1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 294,
1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 328,
1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 355,
1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 374,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 384};
float *GauseSeidel(float *,int);
x=GauseSeidel((float *)c,10);
for(i=0;i <=9;i++)
printf( "x[%d]=%f\n ",i,x[i]);
getch();
}
[解决办法]
楼上,Matrix Class是要下载的吗?下载不了啊!!

===================

居然下载不了? 那你去我的Blog看看

http://blog.csdn.net/LeoMaya/archive/2007/05/14/1608612.aspx

热点排行