当前位置:网站首页>Application of Gauss elimination
Application of Gauss elimination
2022-07-26 09:32:00 【Run away】
Gauss elimination is used to solve System of linear equations Of , That is, it can solve the problem that can be converted into a system of linear equations :
n Solve the problem of dimension Center
We know that n On the Uygur ball n+1 A little bit , It can be solved n Coordinates of the center of the sphere .
hypothesis , Known on the circle (2 Dimension ball ) Three points :
( a 1 , b 1 ) , ( a 2 , b 2 ) , ( a 3 , b 3 ) (a_1,b_1),(a_2,b_2),(a_3,b_3) (a1,b1),(a2,b2),(a3,b3)
Then we can get the equations :
{ ( x − a 1 ) 2 + ( y − b 1 ) 2 = r 2 ( x − a 2 ) 2 + ( y − b 2 ) 2 = r 2 ( x − a 3 ) 2 + ( y − b 3 ) 2 = r 2 \begin{cases} (x-a_1)^2 + (y-b_1)^2 = r^2 \\(x-a_2)^2 + (y-b_2)^2 = r^2 \\(x-a_3)^2 + (y-b_3)^2 = r^2 \end{cases} ⎩⎪⎨⎪⎧(x−a1)2+(y−b1)2=r2(x−a2)2+(y−b2)2=r2(x−a3)2+(y−b3)2=r2
Do a subtraction conversion :
{ 2 ( a 1 − a 2 ) x + 2 ( b 1 − b 2 ) y = ( a 1 2 − a 2 2 ) + ( b 1 2 − b 2 2 ) 2 ( a 2 − a 3 ) x + 2 ( b 2 − b 3 ) y = ( a 2 2 − a 3 2 ) + ( b 2 2 − b 3 2 ) \begin{cases} 2(a_1-a_2)x + 2(b_1-b_2)y = (a_1^2 - a_2^2) + (b_1^2 - b_2^2) \\2(a_2-a_3)x + 2(b_2-b_3)y = (a_2^2 - a_3^2) + (b_2^2 - b_3^2) \end{cases} { 2(a1−a2)x+2(b1−b2)y=(a12−a22)+(b12−b22)2(a2−a3)x+2(b2−b3)y=(a22−a32)+(b22−b32) This is the well-known system of linear equations , And then gauss That's it .
Expand to n dimension :
{ 2 ( a 1 − a 2 ) x + 2 ( b 1 − b 2 ) y + … + 2 ( z 1 − z 2 ) p = ( a 1 2 − a 2 2 ) + ( b 1 2 − b 2 2 ) + … + ( z 1 2 − z 2 2 ) 2 ( a 2 − a 3 ) x + 2 ( b 2 − b 3 ) y + … + 2 ( z 2 − z 3 ) p = ( a 2 2 − a 3 2 ) + ( b 2 2 − b 3 2 ) + … + ( z 2 2 − z 3 2 ) … … 2 ( a n − 1 − a n ) x + 2 ( b n − 1 − b n ) y + … + 2 ( z n − 1 − z n ) p = ( a n − 1 2 − a n 2 ) + … + ( z n − 1 2 − z n 2 ) \begin{cases} 2(a_1-a_2)x+2(b_1-b_2)y +… + 2(z_1-z_2)p = (a_1^2 - a_2^2) + (b_1^2 - b _ 2^2)+…+(z_1^2-z_2^2) \\2(a_2-a_3)x + 2(b_2-b_3)y +… + 2(z_2-z_3)p = (a_2^2 - a_3^2) + (b_2^2 - b _ 3^2)+…+(z_2^2-z_3^2) \\…… \\2(a_{n-1}-a_n)x + 2(b_{n-1}-b_n)y +… + 2(z_{n-1}-z_n)p = (a_{n-1}^2 - a_n^2) +…+(z_{n-1}^2-z_n^2) \end{cases} ⎩⎪⎪⎪⎨⎪⎪⎪⎧2(a1−a2)x+2(b1−b2)y+…+2(z1−z2)p=(a12−a22)+(b12−b22)+…+(z12−z22)2(a2−a3)x+2(b2−b3)y+…+2(z2−z3)p=(a22−a32)+(b22−b32)+…+(z22−z32)……2(an−1−an)x+2(bn−1−bn)y+…+2(zn−1−zn)p=(an−12−an2)+…+(zn−12−zn2)
Example : Spherical space generator
There's a spherical space generator that can be used in n A solid sphere is created in dimensional space .
Now? , You're trapped in this n In the sphere , You only know that on the sphere n+1 Coordinates of points , You need to determine this as quickly as possible n The coordinates of the center of the sphere , In order to destroy this spherical space generator .
Input format
The first line is an integer n.
Next n+1 That's ok , Each row has n A real number , Representing a point on a sphere n Dimensional coordinates .
Every real number is accurate to the decimal point 6 position , And its absolute value does not exceed 20000.
Output format
There is only one line , Give the center of the ball in turn n Dimensional coordinates (n A real number ), Two real numbers are separated by a space .
Every real number is accurate to the decimal point 3 position .
The data is guaranteed to have a solution .
Data range
1≤n≤10
sample input :
2
0.0 0.0
-1.0 1.0
1.0 0.0
sample output :
0.500 1.500
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int maxn = 110;
const int inf = 0x3f3f3f3f3f;
const double eps = 1e-7;
int n;
double a[maxn][maxn];
double b[maxn][maxn];
void gauss(){
double del;
for(int i=1;i<=n;i++){
int k=i;
for(int j=i+1;j<=n;j++){
if(fabs(a[j][i])>fabs(a[k][i]))
k=j;
}
if(fabs(del=a[k][i])<eps) continue;
if(i!=k){
for(int j=i;j<=n+1;j++)
swap(a[i][j],a[k][j]);
}
for(int j=i;j<=n+1;j++) a[i][j]/=del;
for(k=1;k<=n;k++){
if(k!=i){
del=a[k][i];
for(int j=i;j<=n+1;j++)
a[k][j] -= a[i][j]*del;
}
}
}
for(int i=1;i<=n;i++){
printf("%.3f ",a[i][n+1]/a[i][i]);
}
}
int main(void)
{
scanf("%d",&n);
for(int i=1;i<=n+1;i++){
for(int j=1;j<=n;j++){
scanf("%lf",&b[i][j]);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
a[i][j] = 2.0*(b[i][j]-b[i+1][j]);
a[i][n+1] += (b[i][j]*b[i][j]-b[i+1][j]*b[i+1][j]);
}
}
gauss();
return 0;
}
边栏推荐
- 小程序纪录
- Drawing shadow error diagram with MATLAB
- V-permission add permission
- asp.net 使用redis缓存
- CSV data file settings of JMeter configuration components
- The difference between thread join and object wait
- Antd treeselect gets the value of the parent node
- el-table的formatter属性的用法
- 服务器、客户端双认证(2)
- asp. Net using redis cache (2)
猜你喜欢
小白搞一波深拷贝 浅拷贝
Personality test system V1.0
[MySQL] understand the important architecture of MySQL (I)
v-premission添加权限
keepalived 实现mysql自动故障切换
arcgis的基本使用1
2019 ICPC Asia Yinchuan regional (water problem solution)
Fiddler packet capturing tool for mobile packet capturing
2019 ICPC Asia Yinchuan Regional(水题题解)
Great reward for interview questions
随机推荐
微信小程序AvatarCropper 头像裁剪
JS one line code to obtain the maximum and minimum values of the array
Qt随手笔记(二)Edit控件及float,QString转化、
opencv图像处理
phpexcel导出emoji符号报错
自定义密码输入框,无圆角
Simple pedestrian recognition code to 88% accuracy Zheng Zhedong preparation
使用openLayer画箭头
Fiddler packet capturing tool for mobile packet capturing
The problem of the sum of leetcode three numbers
a-table中的rowSelection清空问题
el-table的formatter属性的用法
opencv 类的使用
OpenCV 表格识别之表格提取(二)
Jmeter配置元件之CSV数据文件设置
C managed and unmanaged
官方颁发的SSL证书与自签名证书结合实现网站双向认证
大二上第三周学习笔记
Mo team learning summary (II)
antd TreeSelect获取父节点的值