本文主要是介绍双点弦截法迭代程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
// 双点弦截法迭代
#include "stdafx.h"
#include <cmath>
#include <iostream>
#include <iomanip>double fx(double x)
{double f = log(x) +2.0/9/(x - 1) - 4.697;//注意用2.0/9, 而不是2/9return f; //f(x) = 0中的f(x)函数形式
}
void main()
{using namespace std;int N = 100,//迭代次数最大值k = 0;//迭代次数实际值double a = 1.04,//(a, b)为x取值区间,可以先用Excel试算法确定大概的范围b = 1.05,epsilon = 0.00001,//允许精度x = b, //初始化delta = b - a,//初始化Oldfx = fx(a),//初始化Newfx = fx(x);//初始化cout<<"x0 = "<<a<<endl;cout<<setw(15)<<"delta"<<setw(15)<<"x"<<setw(15)<<"f(x)"<<endl;cout<<setw(15)<<0<<setw(15)<<a<<setw(15)<<Oldfx<<endl;cout<<setw(15)<<delta<<setw(15)<<x<<setw(15)<<Newfx<<endl;for(int i = 0; i<N; i++)//迭代步骤{
这篇关于双点弦截法迭代程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!