📄 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 + -