用二分法求方程 x的五次方-3x+1=0在(0,1)上的近似解,精确到c=0.001,写出算法和
用二分法求方程x的五次方-3x+1=0在(0,1)上的近似解,精确到c=0.001,写出算法和算法语句...
用二分法求方程 x的五次方-3x+1=0在(0,1)上的近似解,精确到c=0.001,写出算法和算法语句
展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double calculate(double middle) //将值代入表达式求表达式的结果
{
return (pow(middle, 5) - 3 * middle + 1);
}
int main(void)
{
double lower = 0.0;
double high = 1.0;
double middle1 = (lower + high) / 2.0;
double middle2 = 0;
while (abs(middle1 - middle2) >= 0.001) //如果前后两次中值之差 >= 0.001,就执行循环
{
if (calculate(middle1) > 0) //表达式的值大于0,将其中值middle1赋给high
{
high = calculate(middle1);
}
else
lower = middle1;
middle2 = middle1;
middle1 = (lower + high) / 2.0;
}
printf("%lg\n", middle1);
return 0;
}
#include <stdlib.h>
#include <math.h>
double calculate(double middle) //将值代入表达式求表达式的结果
{
return (pow(middle, 5) - 3 * middle + 1);
}
int main(void)
{
double lower = 0.0;
double high = 1.0;
double middle1 = (lower + high) / 2.0;
double middle2 = 0;
while (abs(middle1 - middle2) >= 0.001) //如果前后两次中值之差 >= 0.001,就执行循环
{
if (calculate(middle1) > 0) //表达式的值大于0,将其中值middle1赋给high
{
high = calculate(middle1);
}
else
lower = middle1;
middle2 = middle1;
middle1 = (lower + high) / 2.0;
}
printf("%lg\n", middle1);
return 0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询