解方程x *x *x - 5.0 *x *x + 16.0 *x - 80.0 下面是程序,谁给我讲讲原理啊#include #include float f(float x){float y;y = x *x *x - 5.0 *x *x + 16.0 *x - 80.0;return y; }float xpoint(float x1,float x2){float y;y = (x1 *f(x2) -x2 *f(x1))/(f

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/16 06:41:24
解方程x*x*x-5.0*x*x+16.0*x-80.0下面是程序,谁给我讲讲原理啊#include#includefloatf(floatx){floaty;y=x*x*x-5.0*x*x+16.0

解方程x *x *x - 5.0 *x *x + 16.0 *x - 80.0 下面是程序,谁给我讲讲原理啊#include #include float f(float x){float y;y = x *x *x - 5.0 *x *x + 16.0 *x - 80.0;return y; }float xpoint(float x1,float x2){float y;y = (x1 *f(x2) -x2 *f(x1))/(f
解方程x *x *x - 5.0 *x *x + 16.0 *x - 80.0 下面是程序,谁给我讲讲原理啊
#include
#include
float f(float x)
{
float y;
y = x *x *x - 5.0 *x *x + 16.0 *x - 80.0;
return y;
}
float xpoint(float x1,float x2)
{
float y;
y = (x1 *f(x2) -x2 *f(x1))/(f(x2) -f(x1));
return y;
}
float root(float x1,float x2)
{
int i;
float x,x0,y,y1,y2;
y1 =f(x1);
do
{
x = xpoint(x1,x2);
y = f(x);
if(y *y1 > 0)
{
y1 = y;
x1 = x;
}
else
x2 =x;
}while(fabs(y)>= 0.0001);
return x;
}
int main(void)
{
float x1,x2,f1,f2,x;
do
{
printf("请输入x1,x2:");
scanf("%f,%f",&x1,&x2);
f1 = f(x1);
f2 = f(x2);
}while(f1 * f2 >=0);
x = root(x1,x2);
printf("方程的根为:x = %g\n",x);
getchar();
getchar();
}
y = (x1 *f(x2) -x2 *f(x1))/(f(x2) -f(x1));
所有语法都能看懂

解方程x *x *x - 5.0 *x *x + 16.0 *x - 80.0 下面是程序,谁给我讲讲原理啊#include #include float f(float x){float y;y = x *x *x - 5.0 *x *x + 16.0 *x - 80.0;return y; }float xpoint(float x1,float x2){float y;y = (x1 *f(x2) -x2 *f(x1))/(f
就是先随便取2个x的值(x1,x2),算出y的值(y1,y2),如果y1*y2