高斯消元法求方程
来源:互联网 发布:c语言高级编程视频 编辑:程序博客网 时间:2024/04/28 07:21
/** 高斯消元法求方程
* Gaussian elimination with partial pivoting
* @param A为系数矩阵
* @param b
{
for (int p = 0; p < N; p++)
{
// find pivot row and swap
int max = p;
for (int i = p + 1; i < N; i++)
{
if (Math.abs(A[i][p]) > Math.abs(A[max][p]))
{
max = i;
}
}
float[] temp = A[p]; A[p] = A[max]; A[max] = temp;
float t = b[p]; b[p] = b[max]; b[max] = t;
// singular or nearly singular
if (Math.abs(A[p][p]) <= EPSILON)
{
throw new RuntimeException("Matrix is singular or nearly singular");
}
// pivot within A and b
for (int i = p + 1; i < N; i++)
{
float alpha = A[i][p] / A[p][p];
b[i] -= alpha * b[p];
for (int j = p; j < N; j++)
{
A[i][j] -= alpha * A[p][j];
}
}
}
// back substitution
float[] x = new float[N];
for (int i = N - 1; i >= 0; i--)
{
float sum = 0.0f;
for (int j = i + 1; j < N; j++)
{
sum += A[i][j] * x[j];
}
x[i] = (b[i] - sum) / A[i][i];
}
return x;
}
* Gaussian elimination with partial pivoting
* @param A为系数矩阵
* @param b
* @return 计算结果
*/
public static float[] GSolveE(float[][] A, float[] b){
private static final float EPSILON = (float) 1e-10;
int N = b.length;
for (int p = 0; p < N; p++)
{
// find pivot row and swap
int max = p;
for (int i = p + 1; i < N; i++)
{
if (Math.abs(A[i][p]) > Math.abs(A[max][p]))
{
max = i;
}
}
float[] temp = A[p]; A[p] = A[max]; A[max] = temp;
float t = b[p]; b[p] = b[max]; b[max] = t;
// singular or nearly singular
if (Math.abs(A[p][p]) <= EPSILON)
{
throw new RuntimeException("Matrix is singular or nearly singular");
}
// pivot within A and b
for (int i = p + 1; i < N; i++)
{
float alpha = A[i][p] / A[p][p];
b[i] -= alpha * b[p];
for (int j = p; j < N; j++)
{
A[i][j] -= alpha * A[p][j];
}
}
}
// back substitution
float[] x = new float[N];
for (int i = N - 1; i >= 0; i--)
{
float sum = 0.0f;
for (int j = i + 1; j < N; j++)
{
sum += A[i][j] * x[j];
}
x[i] = (b[i] - sum) / A[i][i];
}
return x;
}
0 0
- 高斯消元法求方程
- 方程
- 方程
- 方程
- 求解方程
- 解方程
- 平面方程
- 方程证明
- 参数方程
- 平面方程
- 高斯消元法解方程
- 方程求根
- 传输方程
- 解方程
- 特征方程
- 渲染方程
- 解超定方程
- 方程求解
- Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果
- Matlab的各种数据读取、文件读写等操作汇总
- Linux 高可用(HA)集群之keepalived详解
- 信息理论-第二章
- 【jsoup的学习礼记】设置一个元素的HTML内容
- 高斯消元法求方程
- 大家都用过百度,当你搜索一个词的时候,百度会给你列出好多结果
- AutoCompleteTextView使用3
- C++ 虚函数表解析
- 计算机视觉目标检测的框架与过程
- OpenGL ES渲染之 Shader准备 和 LayerColor
- Android报Didn't find class "com。。。MainActivity" on path: DexPathList错误
- Leetcode: Symmetric Tree
- C# 如何操纵teechart的图形化editing菜单向axtChart中添加mark tip