当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Codeforces Round #798 (Div. 2)ABCD
Go 要加个箭头语法,这下更像 PHP 了!
Do you agree that the salary of hardware engineers is falsely high?
ST表学习
Brief request process
Private computing fat core concepts and stand-alone deployment
Brief introduction to memory structure of virtual machine
Record several interesting XSS vulnerability discoveries
Redis相关
Web3和NFT中的匿名性问题
随机推荐
flutter简单优秀的开源dialog使用free_dialog
COM的模式变化引起的IPdu Handling【接收截止日期监控】
Database learning notes (Chapter 15)
winform 解决黑屏 频繁刷新
微众银行OSPO建设之路:如何通过OSPO的建设推动企业开源?
Finally, the monthly income is 20000!!
Codeforces Round #798 (Div. 2)ABCD
[cloud enjoying freshness] community weekly · vol.66- Huawei partners and Developers Conference 2022 wonderful agenda announcement
Alibaba's employees decreased by 4000 in the first quarter; Programmers wrote scripts to hang up vaccine numbers and were arrested for making a profit of 400000 yuan; Sohu encounters epic email fraud,
IDEA远程调试spark-submit提交的jar
Web3和NFT中的匿名性问题
ADG standby mrp0 status wait_ FOR_ GAP
第六章 I/O管理作业
避免让转型企业走入歧途,是时候重新理解下湖仓一体了!| Q推荐
Wait for someone with "source" | openharmony growth plan student challenge registration to start
文件夹数据同步工具Sync Folders Pro
Develop a basic module with low code
什么是400G以太网?
d求值两次map
Nature communications - modeling armed conflict risk under climate change using machine learning and time series data