//黄金分割法!
/*
================================================================
题目:用黄金分割法求解3*x*x*x-2*x*x-16=0的根。
================================================================
*/
#include<stdio.h>
#include <math.h>
#define E 1e-8
double hs(double x)
{
return 3*x*x*x-2*x*x-16;
}
double gen(double a,double b)
{
double x,fx,fa,fb,g;
g=(sqrt(5)-1.0)/2;
fa=hs(a);
fb=hs(b);
while(fabs(b-a)>E)
{
x=g*(b-a)+a;
fx=hs(x);
if(fa*fx>0)
/*
================================================================
题目:用黄金分割法求解3*x*x*x-2*x*x-16=0的根。
================================================================
*/
#include<stdio.h>
#include <math.h>
#define E 1e-8
double hs(double x)
{
return 3*x*x*x-2*x*x-16;
}
double gen(double a,double b)
{
double x,fx,fa,fb,g;
g=(sqrt(5)-1.0)/2;
fa=hs(a);
fb=hs(b);
while(fabs(b-a)>E)
{
x=g*(b-a)+a;
fx=hs(x);
if(fa*fx>0)