当前位置:网站首页>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;
}
边栏推荐
- I'm faded
- asp.net 使用redis缓存(二)
- Node 内存溢出及V8垃圾回收机制
- Wechat applet avatarcropper avatar clipping
- 高斯消元
- Personality test system V1.0
- 面试题目大赏
- 高斯消元求解异或线性方程组
- EOJ 2020 1月月赛 E数的变换
- After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"
猜你喜欢
随机推荐
asp.net 使用redis缓存
v-for动态设置img的src
Basic use of Arc GIS 2
服务器环境配置全过程
The difference between thread join and object wait
高斯消元求解矩阵的逆(gauss)
WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
Windows backs up the database locally by command
What are CSDN spaces represented by
Does volatile rely on the MESI protocol to solve the visibility problem? (top)
Global variables in DLL
选择器的使用
POJ 1012 Joseph
asp.net 使用redis缓存(二)
Jmeter配置元件之CSV数据文件设置
高斯消元的应用
The provincial government held a teleconference on safety precautions against high temperature weather across the province
Force deduction brush questions, sum of three numbers
服务器、客户端双认证
Solve "note: one or more layouts are missing the layout_width or layout_height attributes."









