对于$x_{k+1} = g(x_k)$,$g$是不动点为$f(x)=0$的解函数
#include<iostream>
#include<string>
#include<cmath>
#define N 50 //最大迭达次数
using namespace std;
double f(double x) //目标函数
{
return 1 + 0.5 * sin(x);
}
void work(double x0)
{
double x = x0;
for (int i = 1; i <= N; i++)
x = f(x);
cout << x << endl;
return;
}
int main()
{
double x0;
cin >> x0;
work(x0);
return 0;
}
Comments NOTHING