> 数学 >
编写程序,用牛顿切线法求方程f(x)=x^3+2x+10=0的近似实根r,迭代初值为-1,精确到0.0001.
人气:170 ℃ 时间:2020-05-03 14:07:48
解答
#include
#include
float f(float x)
{
float y;
y=x*x*x+2*x+10;
return(y);
}
float f1(float x)
{
float y;
y=3*x*x+2;
return(y);
}
void main()
{
float x0=-1.0,x1;
while(fabs(x1-x0) >=0.0001)
{
x1=x0-f(x0)/f1(x0);
x0=x1;
}
printf("%f",x1);
}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版