转完了,但你的程序本身就有二个错误 ,所以没有测试.你自己看着办吧.
其中有一个错误也许是我的理解问题.
第一个错误是致命错误.你自己慢慢改吧.
Option Explicit
Option Base 0
'默认下标设为0 ,与C兼容
Private Sub Command1_Click()
'#include"math.h"
'#include"stdio.h"
'main()
'{
'int i,j,k,n;
Dim i As Integer, j As Integer, k As Integer, n As Integer
'static double a[5]={0.92,0.6,0.58,0.41,0.10};
Dim a As Variant
'注,VB不支持在定义时直接赋值.如果直接对数组赋值,就要求变量定义为 Variant(变体类型),再使用 Array 建立数组
a = Array(0.92, 0.6, 0.58, 0.41, 0.1, 0.1)
'数据个数决定数组元素个数,无法直接指定个数,所以就必须补齐6个数,才能得到 a(0 to
5 )
'static double b[5]={0.7,0.58,0.43,0.35,0.228};
Dim b As Variant
b = Array(0.7, 0.58, 0.43, 0.35, 0.228, 0.228)
'static double d[5]={0.345,0.005,0.065,0.115,0.230};
Dim d As Variant
d = Array(0.345, 0.005, 0.065, 0.115, 0.23, 0.23)
'
double t[7],xt[7],ta,aw,r[5],aaw,la[5],cc,eps,qloss;
Dim t(7) As Double, xt(7) As Double, ta As Double
Dim aw As Double, r(5) As Double, aaw As Double
Dim la(5) As Double, cc As Double, eps As Double, qloss As Double
'
xt[0]=1720.0;
t[0]=1720; eps=0.0001; ta=293;
xt(0) = 1720#: t(0) = 1720: eps = 0.0001: ta = 293
'
aaw=2.56;
aaw = 2.56
'for(i=1;i<7;i++)
t[i]=720;
For i = 1 To 7
t(i) = 720
Next i
'j=0;
j = 0
'do{
Do
'j=j+1;
j = j + 1
'for(i=0;i<5;i++)
For i = 0 To 5
'
la[i]=a[i]+b[i]*(t[i]+t[i+1])/2/1000;
la(i) = a(i) + b(i) * (t(i) + t(i + 1)) / 2 / 1000
Next i
'
for(i=0;i<5;i++)
'r[i]=la[i]/d[i];
For i = 0 To 5
r(i) = la(i) / d(i)
Next i
'for(i=1;i<5;i++)
'xt[i]=r[i-1]/(r[i-1]+r[i])*xt[i-1]+r[i]/(r[i-1]+r[i])*t[i+1];
For i = 1 To 5
xt(i) = r(i - 1) / (r(i - 1) + r(i)) * xt(i - 1) + r(i) / (r(i - 1) + r(i)) * t(i + 1)
Next i
'aw=aaw*pow((t[5]-ta),0.25)+4.54*(pow((t[5]/100),4)-pow
'((ta/100),4))/(t[5]-ta
aw = aaw * Int((t(5) - ta)) ^ 0.25 + 4.54 * (t(5) / 100) ^ 4 - (ta / 100) ^ 4 / (t(5) - ta)
'注,C原代码未结束,没有分号,表达式也未完成,少括号
'pow 计算幂, VB 里对应的运算符是 ^
'xt[5]=r[4]/(aw+r[4])*xt[4]+aw/(aw+r[4])*ta;
xt(5) = r(4) / (aw + r(4)) * xt(4) + aw / (aw + r(4)) * ta
'k=0; for(i=1;i<6;i++)
k = 0
'For i = 1 To 6
'C原代码错,重复的循环结束
'for(i=1;i<6;i++)
For i = 1 To 6
'{ cc=abs(xt[i]-t[i]);
'if(cc>eps) k=k+1;
'
}
cc = Abs(xt(i) - t(i))
If cc > eps Then k = k + 1
Next i
'for(i=0;i<6;i++)
For i = 0 To 6
't[i]=xt[i];
t(i) = xt(i)
Next i
'}while(k>0);
Loop While k > 0
'
qloss=la[0]/d[0]*(t[0]-t[1]);
qloss = la(0) / d(0) * (t(0) - t(1))
'
for(i=0;i<6;i++)
For i = 0 To 6
'
printf("tt(%d)=%e\n",i,xt[i]);
Print "tt "; i; "="; xt(i)
Next i
'
printf("qloss=%e,%d\n",qloss,j);
Print "qloss="; qloss; j
'
}
'计算结果是计算结果
'T [1] = 1720
'T [2] = 1478
'T [3] = 1474
'T [4] = 1413
'T [5] = 1267
'T [5] = 371
End Sub