用迭代法就可以了。 把方程转换为 h=F(h)这种样式,然后利用迭代公式 h[i+1]=F(h[i]) 随便取一个初始值作为h[0],不停的迭代 如果h[i+1]和h[i]足够接近,就认为h[i]是解。大致的代码是:function myPower(e1, e2: Extended): Extended; begin if e1=0 then Result:= 0 else if e1>0 then Result:= power(e1, e2) else Result:= -power(-e1, e2); end ;function formula(h: Double): Double; var dbl1, dbl2, dbl3: Double; begin dbl1:=mypower(h*h-1,5.0/3.0); dbl2:=mypower(2*h+1,2.0/3.0); dbl3:=mypower((10-dbl1/dbl2)/4, 3.0/5.0); Result:= (1-dbl3)/3; end ; procedure TForm1.Button2Click(Sender: TObject); var h1, h2: Double; begin h1:= 1; h2:= formula(h1); while abs(h1-h2)>1e-6 do begin h1:= h2; h2:= formula(h1); end ; showMessage(floatToStr(h1)); end;
把方程转换为
h=F(h)这种样式,然后利用迭代公式
h[i+1]=F(h[i])
随便取一个初始值作为h[0],不停的迭代
如果h[i+1]和h[i]足够接近,就认为h[i]是解。大致的代码是:function myPower(e1, e2: Extended): Extended;
begin
if e1=0 then
Result:= 0
else if e1>0 then
Result:= power(e1, e2)
else
Result:= -power(-e1, e2);
end ;function formula(h: Double): Double;
var
dbl1, dbl2, dbl3: Double;
begin
dbl1:=mypower(h*h-1,5.0/3.0);
dbl2:=mypower(2*h+1,2.0/3.0);
dbl3:=mypower((10-dbl1/dbl2)/4, 3.0/5.0);
Result:= (1-dbl3)/3;
end ;
procedure TForm1.Button2Click(Sender: TObject);
var
h1, h2: Double;
begin
h1:= 1;
h2:= formula(h1);
while abs(h1-h2)>1e-6 do
begin
h1:= h2;
h2:= formula(h1);
end ;
showMessage(floatToStr(h1));
end;