全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1260
推到 Plurk!
推到 Facebook!

一個數學算式在delphi如何實現請大家幫幫忙

答題得分者是:junlin
AVA
一般會員


發表:1
回覆:1
積分:0
註冊:2008-08-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-08-04 19:22:14 IP:61.228.xxx.xxx 訂閱
個人剛學delphi不久
想把之前用excel巨集寫的算式
用delphi來做
主要是想用edit1,edit2輸入2個數值(Q和P)後
在label1來呈現結果
卻一直做不出來
以下為excel vb裡的源碼

Function Dh(Q, P)
D = 0
Do
D = D 1
A = 3.1415927 * (D / 1000) ^ 2 / 4
V = Q / A
Re = 66.4 * D * V
f = 0.11 * ((0.15 / D) (68 / Re)) ^ 0.25
If f < 0.018 Then
f = 0.85 * f 0.0028
End If
Pm = 1000 * f * 1.2 * V ^ 2 / D / 2
dP = P - Pm
Loop Until dP > 0
Dh = D
End Function
我有嘗試去做
但一直出錯
請大家幫幫忙拍導一下
junlin
初階會員


發表:66
回覆:94
積分:42
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-08-05 10:01:27 IP:220.130.xxx.xxx 訂閱

[code delphi]
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(floattostr(dh(10,20)));
end;

Function TForm1.Dh(Q, P:double):double;
var D, A, V, Re, f, Pm, dP:double;
begin
D:= 0;

repeat
D:= D 1;
A:= 3.1415927 * power((D / 1000),2) / 4;
V:= Q / A;
Re:= 66.4 * D * V;
f:= 0.11 * power(((0.15 / D) (68 / Re)),0.25);
If f < 0.018 Then f := 0.85 * f 0.0028;

Pm := 1000 * f * 1.2 * power(V,2) / D / 2;
dP := P - Pm;
Until dP > 0;
result := D;
end;

[/code]
AVA
一般會員


發表:1
回覆:1
積分:0
註冊:2008-08-04

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-08-05 20:02:18 IP:61.228.xxx.xxx 訂閱

===================引 用 junlin 文 章===================

[code delphi]
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(floattostr(dh(10,20)));
end;

Function TForm1.Dh(Q, P:double):double;
var D, A, V, Re, f, Pm, dP:double;
begin
D:= 0;

repeat
D:= D 1;
A:= 3.1415927 * power((D / 1000),2) / 4;
V:= Q / A;
Re:= 66.4 * D * V;
f:= 0.11 * power(((0.15 / D) (68 / Re)),0.25);
If f < 0.018 Then f := 0.85 * f 0.0028;

Pm := 1000 * f * 1.2 * power(V,2) / D / 2;
dP := P - Pm;
Until dP > 0;
result := D;
end;

[/code]


我直接照copy然後執行後
showmessage(floattostr(dh(10,20))); 這行就出現錯誤;這行應該是顯示結果吧

另外Q,P值是要由何處輸入(是拍令中哪一行? 我真的不懂..不要笑我....)
不需要用到Q:=strtoint(edit1.text);和P:=strtiint(edit2.text); 來建立輸入值?
請在指教..謝謝
christie
資深會員


發表:30
回覆:299
積分:475
註冊:2005-03-25

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-08-06 13:31:00 IP:203.73.xxx.xxx 未訂閱

===================引 用 junlin 文 章===================

[code delphi]
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(floattostr(dh(10,20)));
end;

Function TForm1.Dh(Q, P:double):double;
var D, A, V, Re, f, Pm, dP:double;
begin
D:= 0;

repeat
D:= D 1;
A:= 3.1415927 * power((D / 1000),2) / 4;
V:= Q / A;
Re:= 66.4 * D * V;
f:= 0.11 * power(((0.15 / D) (68 / Re)),0.25);
If f < 0.018 Then f := 0.85 * f 0.0028;

Pm := 1000 * f * 1.2 * power(V,2) / D / 2;
dP := P - Pm;
Until dP > 0;
result := D;
end;

[/code]
修改一下junlin
請試試看
..
..

implementation
{$R *.dfm}
Function Dh(Q, P:double):double;
var
D, A, V, Re, f, Pm, dP:double;
begin
D:= 0;
repeat
D:= D 1;
A:= 3.1415927 * power((D / 1000),2) / 4;
V:= Q / A;
Re:= 66.4 * D * V;
f:= 0.11 * power(((0.15 / D) (68 / Re)),0.25);
If f < 0.018 Then f := 0.85 * f 0.0028;
Pm := 1000 * f * 1.2 * power(V,2) / D / 2;
dP := P - Pm;
Until dP > 0;
result := D;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(floattostr(dh(10,20)));
end;

------
What do we live for if not to make life less difficult for each other?
junlin
初階會員


發表:66
回覆:94
積分:42
註冊:2002-03-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-08-06 17:32:23 IP:61.220.xxx.xxx 訂閱
完整的pas檔, 你自己要記得在form上面拉2個Edit, 分別給USER輸入Q和P

[code delphi]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Function Dh(Q, P:double):double; //Function declare
end;

var
Form1: TForm1;

implementation
{$R *.dfm}
uses math; //記得要加這行power用
procedure TForm1.Button1Click(Sender: TObject);
var Q, P:Double;
begin
Q:=strtofloat(edit1.text);
P:=strtofloat(edit2.text);
showmessage(floattostr(dh(Q,P)));
end;

Function TForm1.Dh(Q, P:double):double;
var D, A, V, Re, f, Pm, dP:double;
begin
D:= 0;
repeat
D:= D 1;
A:= 3.1415927 * power((D / 1000),2) / 4;
V:= Q / A;
Re:= 66.4 * D * V;
f:= 0.11 * power(((0.15 / D) (68 / Re)),0.25);
If f < 0.018 Then f := 0.85 * f 0.0028;
Pm := 1000 * f * 1.2 * power(V,2) / D / 2;
dP := P - Pm;
Until dP > 0;
result := D;
end;


end.

[/code]
系統時間:2024-04-29 1:49:51
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!