AttributeError
该程序似乎无法将#include <stdio.h>
#include <conio.h>
#include <math.h>
#define ESP 0.0001
#define F(x) x^3-2.5x^2-1.8x+2.356
void main()
{
float x0,x1,x2,f1,f2,f0;
int count=0;
do
{
printf("\nEnter the value of x0: ");
scanf("%f",&x0);
}while(F(x0) > 0);
do
{
printf("\nEnter the value of x1: ");
scanf("%f",&x1);
}while(F(x1) < 0);
printf("\n__________________________________________________________\n");
printf("\n x0\t x1\t x2\t f0\t f1\t f2");
printf("\n__________________________________________________________\n");
do
{
f0=F(x0);
f1=F(x1);
x2=x0-((f0*(x1-x0))/(f1-f0));
f2=F(x2);
printf("\n%f %f %f %f %f %f",x0,x1,x2,f0,f1,f2);
if(f0*f2<0)
{
x1=x2;
}
else
{
x0 = x2;
}
}while(fabs(f2)>ESP);
printf("\n__________________________________________________________\n");
printf("\n\nApp.root = %f",x2);
getch();
}
视为功能,但当我使用#define F(x) x^3-2.5x^2-1.8x+2.356
时,没有错误。
我试过#define F(x) 3*(x) - 1 - cos(x)
,没有运气。
答案 0 :(得分:0)
F(x)x ^ 3-2.5x ^ 2-1.8x + 2.356
float F(float x)
{
return x * x * x + 2.5f * x * x + 1.8f * x + 2.356f;
}