当前位置:网站首页>高斯消元求n元方程组
高斯消元求n元方程组
2022-06-13 10:57:00 【重生之我会拧瓶盖】
#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;
}
边栏推荐
猜你喜欢
Some experience in database table structure design

Install Kubernetes 1.24

To vent their dissatisfaction with their superiors, Baidu post-95 programmers were sentenced to 9 months for deleting the database

Database learning notes (Chapter 16)

Go needs to add an arrow syntax, which is more like PHP!

技术管理进阶——管理者可以使用哪些管理工具

Pagoda access changed from IP to domain name

Vivo large scale kubernetes cluster automation operation and maintenance practice

IDEA远程调试spark-submit提交的jar

Necessary for Architects: system capacity status checklist
随机推荐
Actual combat simulation │ real time error alarm of enterprise wechat robot
Database learning notes (Chapter 16)
第七章 文件管理作业
vivo大规模 Kubernetes 集群自动化运维实践
Vivo large scale kubernetes cluster automation operation and maintenance practice
Matplotlib 学习笔记
Vivo large scale kubernetes cluster automation operation and maintenance practice
Codeforces Round #798 (Div. 2)ABCD
Acwing game 55
Develop a basic module with low code
vivo大规模 Kubernetes 集群自动化运维实践
Do you agree that the salary of hardware engineers is falsely high?
中国SaaS产业全景图谱
测试人员必须掌握的测试用例
Actual combat analysis of malicious code lab05-01
MySQL transaction isolation level and mvcc
记一次水平越权漏洞的利用
Solution to qt5.12 unable to input Chinese (unable to switch Chinese input method) in deepin system
of_find_compatible_node查找出所有的节点
Database system concept (Chapter 17)