高斯赛德尔迭代法
来源:互联网 发布:优秀的java开源项目 编辑:程序博客网 时间:2024/05/17 07:17
// 高斯赛德尔迭代法.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "math.h"
#include<iostream>
using namespace std;
int main()
{
//输入
int k = 1;
int N; //最大迭代次数
double x[200], y[200], b[200], d[200];
double e, n, sum1, sum2, max;
double a[200][200];
cout << "请输入阶数" << endl;
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "请依次输入系数矩阵第" << i + 1 << "行的" << n << "个数" << endl;
for (int j = 0; j < n; j++)
{
cin >> a[i][j];
}
}
cout << "请依次输入" << n << "个等式右面的系数" << endl;
for (int i = 0; i < n; i++){
cin >> b[i];
}
cout << "请输入最大迭代次数" << endl;
cin >> N;
cout << "请输入精度值" << endl;
cin >> e;
//计算
do
{
for (i = 1; i <= n; i++)//***
{
for (int j = 1; j <= (i - 1); j++)//***
{
m = m + a[i][j] * y[j];//***
}
for (int j = (i + 1); j <= n; j++)
{
z = z + a[i][j] * y[j];
}
y[i] = (b[i] - m - z) / a[i][i];
cout << "y" << i << "=" << y[i] << endl;
}
//判断
double max = 0;
for (i = 1; i <= n; i++)
{
if (fabs(x[i] - y[i]) > max)
{
max = fabs(x[i] - y[i]);
}
}
cout << "max=" << max << endl;
//输出
if (max <= e)
{
for (int i = 1; i <= n; i++)
{
cout << "y" << i << "=" << y[i] << endl;
}
break;
}
k++;
for (int i = 1; i <= n; i++)
{
x[i] = y[i];
}
if (k == N)
{
cout << "迭代失败!" << endl;
}
} while (k != N);
getchar();
getchar();
getchar();
getchar();
return 0;
}
//
#include "stdafx.h"
#include "math.h"
#include<iostream>
using namespace std;
int main()
{
//输入
int k = 1;
int N; //最大迭代次数
double x[200], y[200], b[200], d[200];
double e, n, sum1, sum2, max;
double a[200][200];
cout << "请输入阶数" << endl;
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "请依次输入系数矩阵第" << i + 1 << "行的" << n << "个数" << endl;
for (int j = 0; j < n; j++)
{
cin >> a[i][j];
}
}
cout << "请依次输入" << n << "个等式右面的系数" << endl;
for (int i = 0; i < n; i++){
cin >> b[i];
}
cout << "请输入最大迭代次数" << endl;
cin >> N;
cout << "请输入精度值" << endl;
cin >> e;
//计算
do
{
for (i = 1; i <= n; i++)//***
{
for (int j = 1; j <= (i - 1); j++)//***
{
m = m + a[i][j] * y[j];//***
}
for (int j = (i + 1); j <= n; j++)
{
z = z + a[i][j] * y[j];
}
y[i] = (b[i] - m - z) / a[i][i];
cout << "y" << i << "=" << y[i] << endl;
}
//判断
double max = 0;
for (i = 1; i <= n; i++)
{
if (fabs(x[i] - y[i]) > max)
{
max = fabs(x[i] - y[i]);
}
}
cout << "max=" << max << endl;
//输出
if (max <= e)
{
for (int i = 1; i <= n; i++)
{
cout << "y" << i << "=" << y[i] << endl;
}
break;
}
k++;
for (int i = 1; i <= n; i++)
{
x[i] = y[i];
}
if (k == N)
{
cout << "迭代失败!" << endl;
}
} while (k != N);
getchar();
getchar();
getchar();
getchar();
return 0;
}
0 0
- 高斯赛德尔迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法
- 迭代法解方程:牛顿迭代法、Jacobi迭代法
- 牛顿迭代法
- android性能优化
- 改进的欧拉格式法
- 洛谷 P1309 瑞士轮
- 《第一行代码》学习之旅--第二章
- POM文件详解01
- 高斯赛德尔迭代法
- 解决ThinkPHP除去链接中的index.php
- angularJS自定义directive之带参方法传递
- LIBCURL上传文件, 下载文件,打开网页,POST数据,支持https等一系列函数方便各种模拟登陆注册账户
- hdu 2136 素数筛选法
- Spring学习笔记<三> 获取请求对象和请求头
- Mysql limit 优化,百万至千万级快速分页,--复合索
- 签名参数sign生成说明-tencent
- [00305]字节到大整数的打包与解包