C语言 进退法确定极小值区间

2021-01-08 23:33

阅读:655

标签:语言   指针   cti   turn   pre   while   fun   define   c语言   

#include 

#define F(x)	(3*x*x-8*x+9)

double fun1(double x);
void goAndBackSectionPrint(double x1, double h, double (*f)(double));

int main(void){
	goAndBackSectionPrint(0, 0.1, fun1);
	
	return 0;
}

//进退法打印区间
//x1	搜索初值
//h	搜索步长
//f 	待搜索函数f(x)的指针
void goAndBackSectionPrint(double x1, double h, double (*f)(double)){
	double a1 = x1;
	double y1 = (*f)(a1);	
	double a2 = a1 + h;
	double y2 = f(a2);	
	double a3 = 0;
	double y3 = 0;
	
	if(y2 > y1){
		h = -h;
		a3 = a1;
		y3 = y1;
		
		a1 = a2;
		y1 = y2;
		a2 = a3;
		y2 = y3;
	}

	a3 = a2 + h;
	y3 = f(a3);
	
	while(y3 

C语言 进退法确定极小值区间

标签:语言   指针   cti   turn   pre   while   fun   define   c语言   

原文地址:https://www.cnblogs.com/ritchie0307/p/12964045.html


评论


亲,登录后才可以留言!