三分查找

//三分查找(凹函数)

double thirds(double low,double high){
    double f1,f2;
    f1=fiction(low); f2=fiction(high);
    while(fabs(f1-f2)>eps){ 
	double mid1 = low + (high-low)/3;
	double mid2 = high - (high-low)/3;
	f1=fiction(mid1);
	f2=fiction(mid2);
	if(f1<f2)  low = mid1;
	else  if(f1>f2)  high = mid2;
	else if(fabs(f1-f2)<=eps)  low = high; 
    }
}

  

posted on 2013-08-13 21:30  Amyc  阅读(147)  评论(0编辑  收藏  举报