#include<iostream>
#include<cmath>
using namespace std;
double fun(double x)
{
return 3*x*x*x-2*x*x-5;
}
double f(double x)
{
return 9*x*x-4*x;
}
int main( )
{
double root1, root2=1;
do {
root1=root2;
root2= root1-fun(root1)/f(root1);
}while(fabs(root1-root2)>1e-5);
cout<<"方程的根是: "<<root2<<endl;
cout<<fun(root2)<<endl;
system("pause");
return 0;
}
用牛顿迭代法求3x3-2x2-5=0根,求精确到10-5。 牛顿迭代公式:x=x-f(x)/f’(x)。求定义两个函数求f(x)和f’(x)的c++
于 2020-11-17 19:24:20 首次发布