天天看點

求解方程根的近似解:一般疊代法

#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
double f(double x)
{
    return log(4-x)/2;
}
int main()
{
    double x=1,y;
    int count=1;
    do
    {
        y=f(x);
        printf("%-3d: ",count++);
        printf("%-10lf  ",y);
        cout<<endl;
        if(abs(x-y)<10e-5)
            break;
        x=y;
    }while(1);
    return 0;
}
           
求解方程根的近似解:一般疊代法

繼續閱讀