Binary_interval_method
来源:互联网 发布:编程语言学 编辑:程序博客网 时间:2024/06/14 15:39
#include<stdio.h>
#define N 100
float cal(float p)
{
float sum=p*p*p+p-4;
return sum;
}
float main(){
float a;
float b;
float flag;
int n;
float p;
float FP;
float FA;
flag=0.001f;
n=0;
a=1;
b=3;
if((FA=cal(a))==0)
{
return a;
}
if((FP=cal(b))==0)
{
return b;
}
while(n<N||n==N)
{
p=(a+b)/2.0;
FP=cal(p);
n++;
if(FP==0||(b-a)/2.0<flag)
{
printf("x: %f N:%d ok \n",p,n);
return p;
}
else
if(FA*FP>0)
{
a=p;
FA=FP;
}
else
b=p;
}
printf("error\n");
return 0;
}
#define N 100
float cal(float p)
{
float sum=p*p*p+p-4;
return sum;
}
float main(){
float a;
float b;
float flag;
int n;
float p;
float FP;
float FA;
flag=0.001f;
n=0;
a=1;
b=3;
if((FA=cal(a))==0)
{
return a;
}
if((FP=cal(b))==0)
{
return b;
}
while(n<N||n==N)
{
p=(a+b)/2.0;
FP=cal(p);
n++;
if(FP==0||(b-a)/2.0<flag)
{
printf("x: %f N:%d ok \n",p,n);
return p;
}
else
if(FA*FP>0)
{
a=p;
FA=FP;
}
else
b=p;
}
printf("error\n");
return 0;
}
- Binary_interval_method
- 转载 GIS的下个十年(Cary Mann, vice president, Bentley)
- 转载 GIS的下个十年(Chuck Drinnan, principal, eWAM Associates)
- GaussElimination_MCP
- cocos2d-x 开发者大会之cocos2d-x与三国群殴传
- 两个大数相乘
- Binary_interval_method
- 转载 GIS的下个十年(William D. Goran, U.S. Army Corps of Engineers)
- chasingMethod
- android启动过程分析--启动init进程
- Newton
- Scripting Browser Windows --- 1
- secant_method
- google api key无法获取的问题
- 对象的克隆——原型模式(二)