?? c.txt
字號:
#include<stdio.h>
#include<math.h>
#include<conio.h>
float f(float x)
...{
return 2*x*x*x-4*x*x+3*x-6;
}
float fd(float x)
...{
return 6*x*x-8*x+3;
}
int main(void)
...{
float x0=1.5,x=1.5;
do...{
x0=x;
x=x0-f(x0)/fd(x0);//迭代公式求近似根;
}while(fabs(x-x0)>1e-4);
printf("the asymtomatic root is %f ",x0);
getch();
return 0;
}
/**//*2.000005*/二分法:
#include <stdio.h>
#include <math.h>
#include <conio.h>
float f(float x)
...{
return 2*x*x*x-4*x*x+3*x-6;
}
int main(void)
...{
float l=-10,r=10,root,mid;
while(fabs(l-r)>1e-4)...{
mid=(l+r)/2;
if(!f(mid))...{
root=mid;
break;
}if(f(l)*f(mid)<0)
r=mid;
else
l=mid;
}
root=mid;
printf("the only one root is %f ",root);
getch();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -