逐次代入法求解非线性方程
2013-08-07 21:49
204 查看
//用逐次代入法求解非线性方程
#include <iostream>
#include <math.h>
#include <process.h>
using namespace std;
class successive
{
private:
int iteration;
double eps, error, f, x_new, x_old;
public:
successive()
{
iteration = 0;
}
void solution();
double function(double x)
{
f = 0.3 * exp(x);
return f;
}
};
void main()
{
successive substitution;
substitution.solution();
}
void successive::solution()
{
cout << "\n输入初始估值:";
cin >> x_old;
cout << "\n输入公差:";
cin >> eps;
if (fabs(x_old - function(x_old)) < eps)
{
cout << "\n解是:" << x_old << endl;
exit(0);
}
do
{
iteration++;
x_new = function(x_old);
error = fabs(x_new - function(x_new));
x_old = x_new;
}while (error >= eps);
cout << "\n解是:" << x_new << endl;
cout << "\n收敛于" << iteration << "次迭代" << endl;
}
#include <iostream>
#include <math.h>
#include <process.h>
using namespace std;
class successive
{
private:
int iteration;
double eps, error, f, x_new, x_old;
public:
successive()
{
iteration = 0;
}
void solution();
double function(double x)
{
f = 0.3 * exp(x);
return f;
}
};
void main()
{
successive substitution;
substitution.solution();
}
void successive::solution()
{
cout << "\n输入初始估值:";
cin >> x_old;
cout << "\n输入公差:";
cin >> eps;
if (fabs(x_old - function(x_old)) < eps)
{
cout << "\n解是:" << x_old << endl;
exit(0);
}
do
{
iteration++;
x_new = function(x_old);
error = fabs(x_new - function(x_new));
x_old = x_new;
}while (error >= eps);
cout << "\n解是:" << x_new << endl;
cout << "\n收敛于" << iteration << "次迭代" << endl;
}
相关文章推荐
- Newton_Raphson法求解非线性方程
- Newton-Raphson 法求解非线性方程组
- 割线法求解非线性方程
- Python求解非线性方程
- 优化与求解非线性方程组(单变量问题)
- python/scipy求解非线性方程(fsolve/root)
- 数值计算——求解非线性方程组
- 使用matlab进行非线性方程组求解
- fsolve函数求解非线性方程
- python用fsolve、leastsq对非线性方程组进行求解
- 非线性方程组求解算法的C++实现
- R语言非线性方程组求解dfsane,nleqslv
- 用R语言求解非线性方程
- 非线性方程二分法求解
- 对分法(二分法)求解非线性方程-M语言
- 求解多元非线性方程组的解(功分器dB值与功分比转化)
- 非线性方程(组)的求解
- matlab实现牛顿迭代法求解非线性方程组
- 牛顿下山法求解非线性方程(组)(C实现)
- matlab中求解由符号表达式组成的非线性方程组