训练2 习题2
来源:互联网 发布:哪个软件可以看素媛 编辑:程序博客网 时间:2024/06/01 09:52
题目:Now, here is a fuction:<br> F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)<br>Can you find the minimum value when x is between 0 and 100.
思路:求导 又有实际意义知极值为0 是解 用二分法求x 然后求F(x)!
代码:# include <iostream>
# include <cmath>using namespace std;
double f(double x, double y)
{
double fx = 42 * pow(x, 6) + 48 * pow(x, 5) + 21 * pow(x, 2) + 10 * x - y;
return fx;
}
double f1(double x, double y)
{
double fx = 6 * pow(x, 7) + 8 * pow(x, 6) + 7 * pow(x, 3) + 5 * pow(x, 2) - y * x;
return fx;
}
int main()
{
int t;
cin >> t;
while(t--)
{
double y;
cin >> y;
double begin = 0, end = 100, mid;
int i = 0;
while(1)
{
mid = (begin + end) / 2;
if(fabs(f(mid, y)) <= 0.0001)
{
cout.precision(4);
cout << fixed << f1(mid, y) << endl;
break;
}
else if(f(mid, y) > 0)
{
end = mid;
}
else if(f(mid, y) < 0)
{
begin = mid;
}
}
}
return 0;
}
0 0
- 训练2 习题2
- 训练4 习题2
- 习题2
- 习题2
- 习题2
- 习题2
- 习题2
- 习题2
- 习题-2
- 逻辑思维训练习题
- mysql复习 习题训练
- 训练3 习题6
- 训练3 习题10
- 训练3 习题13
- 训练3 习题15
- 训练3 习题1
- 训练3 习题14
- 训练3 习题5
- kmp算法入门,同学写的
- Java代码重构第一步
- 一些常用python预处理方法
- 基数排序
- winCE版本
- 训练2 习题2
- SSH+Tomcat+MySQL项目搭建
- mysql管理工具
- 函数指针的一个例子
- 跟我一起学习MySQL技术内幕(第五版):(第二章学习日记10)
- ZOJ 3947Very Happy Great BG
- HDU1978howmanyways
- 【C语言的递归调用】汉罗塔问题心得
- iOS开发之UIWebView使用总结