当前位置:网站首页>Gauss elimination for solving N-element equations
Gauss elimination for solving N-element equations
2022-06-13 11:02:00 【I can screw the bottle cap when I am born again】
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 110;
const double eps = 1e-6;
int n;
double a[N][N];
int gauss()
{
int c, r;
for (c = 0, r = 0; c < n; c ++ )
{
int t = r;
for (int i = r; i < n; i ++ )
if (fabs(a[i][c]) > fabs(a[t][c]))
t = i;
if (fabs(a[t][c]) < eps) continue;
for (int i = c; i < n + 1; i ++ ) swap(a[t][i], a[r][i]);
for (int i = n; i >= c; i -- ) a[r][i] /= a[r][c];
for (int i = r + 1; i < n; i ++ )
if (fabs(a[i][c]) > eps)
for (int j = n; j >= c; j -- )
a[i][j] -= a[r][j] * a[i][c];
r ++ ;
}
if (r < n)
{
for (int i = r; i < n; i ++ )
if (fabs(a[i][n]) > eps)
return 2;
return 1;
}
for (int i = n - 1; i >= 0; i -- )
for (int j = i + 1; j < n; j ++ )
a[i][n] -= a[j][n] * a[i][j];
return 0;
}
int main()
{
cin >> n;
for (int i = 0; i < n; i ++ )
for (int j = 0; j < n + 1; j ++ )
cin >> a[i][j];
int t = gauss();
if (t == 0)
{
for (int i = 0; i < n; i ++ ) printf("%.2lf\n", a[i][n]);
}
else if (t == 1) puts("Infinite group solutions");
else puts("No solution");
return 0;
}
边栏推荐
- 2022年劳务员-通用基础(劳务员)上岗证题目及答案
- 服务器的使用
- Electrolytic capacitor, tantalum capacitor, ordinary capacitor
- spark源码(一)spark-submit如何将jar以及配置参数提交给spark服务器
- Codeforces Round #798 (Div. 2)ABCD
- Implementation of singleton mode
- 2022甘肃省安全员C证上岗证题目及在线模拟考试
- Easyclick run code snippet out null
- We spent a weekend migrating 3.7 million lines of code to typescript
- Advanced technology management - what management tools can managers use
猜你喜欢
Flutter simple and excellent open source dialog uses free_ dialog
Navicat connection MySQL in Pagoda
欧拉函数和线性筛求欧拉函数
Understand an article: Spark operation mode
Codeforces Round #798 (Div. 2)ABCD
Advanced technology management - what management tools can managers use
Go needs to add an arrow syntax, which is more like PHP!
区间修改乘和加(理解懒标记的好例题)
Folder data synchronization tool sync folders Pro
Full stack development practice | integrated development of SSM framework
随机推荐
2022煤矿探放水特种作业证考试题库模拟考试平台操作
ue5 小知识点 geometry script modeling
Database learning notes (Chapter 16)
Vivo large scale kubernetes cluster automation operation and maintenance practice
Vivo large scale kubernetes cluster automation operation and maintenance practice
求组合数四种方法
Pytorch basis (II) -- tensor and gradient
Flutter simple and excellent open source dialog uses free_ dialog
宝塔中查看mysql默认密码
Necessary for Architects: system capacity status checklist
2022煤矿探放水特种作业证考试题库模拟考试平台操作
文件夹数据同步工具Sync Folders Pro
我们用了一个周末,将 370 万行代码迁移到了 TypeScript
d编译时生成唯一标识
Go needs to add an arrow syntax, which is more like PHP!
作为一个测试人员,这些基础知识必不可少
Idea remote debugging jar submitted by spark submit
Web 3.0?高成本版的P2P而已
[elm classification] data classification based on particle swarm optimization convolution neural network CNN combined with limit learning machine elm with matlab code
Record several interesting XSS vulnerability discoveries