在区间(0,100),二次导数恒大于0,f(x)有极小值,用一次导数求极小值点;
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> const double eps=1e-6; double f(double x,double y) { return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x; } double fpi(double x,double y) { return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y; } double slove(double y) { double left=0.0,right=100.0,mid; while(right-left>eps) { mid=(left+right)/2; if(fpi(mid,y)<0.0) left=mid; else right=mid; } return mid; } int main(void) { int t; double y; scanf("%d",&t); while(t--) { scanf("%lf",&y); printf("%.4f\n",f(slove(y),y)); } return 0; }
原文地址:http://blog.csdn.net/loolu5/article/details/41214791