标题:[原创]列主元消去法解线性方程组c程序
取消只看楼主
zhangzujin
Rank: 1
等 级:新手上路
帖 子:276
专家分:0
注 册:2005-5-9
 问题点数:0 回复次数:0 
[原创]列主元消去法解线性方程组c程序

这个程序很好,调试的和用matlab解的一模一样. 如有兴趣,自己运行一下. #include<stdio.h> #include<conio.h> #include<math.h> #define N 100 #define epsilon 1e-6 float a[N][N+1];

void main( ) { int i,j,k,n; float t,s=0; clrscr( ); printf("It is strongly recommended that you read this before you run the programming:\n"); printf("1.This is Gauss method to solve linear equations.\n"); printf("2.Please review the principles of Gauss method.\n"); printf("3.Be careful,don't just depend on computers,you have mind!\n"); printf("4.Probably there are some defects in this programme.\n"); printf(" If any,please send messages to the creator.\n"); printf("5.Copyright 2005-5-15 Zhang Zujin\n"); printf(" QQ:283421560 E-mail:zhangzujin360732@163.com\n"); printf("Input juzhen jieshu:"); scanf("%d",&n); printf("\n"); printf("Input Extended Matrix:\n"); for(i=0;i<n;i++) for(j=0;j<n+1;j++) scanf("%f",&a[i][j]); for(k=0;k<n-1;k++) { for(i=k+1;i<n;i++) if( abs(a[i][k]) > abs(a[k][k]) ) for(j=k;j<n+1;j++) { t=a[k][j]; a[k][j]=a[i][j]; a[i][j]=t; } if( abs(a[k][k]) < epsilon) { printf("\nError,zhuyuan xiaoqufa cann't be durable,break at %d!\n",k+1); return; } for(i=k+1;i<n;i++) { a[i][k]=a[i][k] / a[k][k]; for(j=k+1;j<n+1;j++) a[i][j]=a[i][j]-a[i][k] * a[k][j]; } } a[n-1][n]=a[n-1][n] / a[n-1][n-1]; for(k=n-2;k>=0;k--) { s=0; for(j=k+1;j<n;j++) s+=a[k][j]*a[j][n]; a[k][n]=( a[k][n]-s ) / a[k][k]; } printf("\n*****The Result*****\n"); for(i=0;i<n;i++) printf(" x[%d]=%.4f\n",i+1,a[i][n]); getch( ); }

搜索更多相关主题的帖子: 线性方程 消去法 
2005-05-16 23:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-18426-1-1.html




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

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