请教各位:
我有一段程序通过matlab计算出的结果和用Excel中VB计算的结果完全不一样,跪求指导。。。。。(已经确定是程序中这段的问题,实在找不出2者的区别)
两种语言中中Ndata=n, inpt(i)= sh.Cells(i + 1, 4)
matlab程序如下:
for i=1:Ndata
if h1>a(9)
q2=a(3).*(h1-a(9));
q1=a(2).*(h1-a(8));
elseif h1>=a(8) && h1<=a(9)
q2=0;
q1=a(2).*(h1-a(8));
else
q1=0;
q2=0;
end
q3=a(4).*h1;
if h2>a(10)
q4=a(5).*(h2-a(10));
else
q4=0;
end
q5=a(6).*h2;
q6=a(7).*h3;
h1=h1+inpt(i)-q1-q2-q3;
h2=h2+q3-q4-q5;
h3=h3+q5-q6;
if h1<0
h1=0;
end
if h2<0
h2=0;
end
if h3<0
h3=0;
end
h3
end
VB如下:
For i = 1 To n
If h1 > a(9) Then
q2 = a(3) * (h1 - a(9))
q1 = a(2) * (h1 - a(8))
ElseIf h1 >= a(8) & h1 <= a(9) Then
q2 = 0#
q1 = a(2) * (h1 - a(8))
Else
q1 = 0#
q2 = 0#
End If
q3 = a(4) * h1
If h2 > a(10) Then
q4 = a(5) * (h2 - a(10))
Else
q4 = 0#
End If
q5 = a(6) * h2
q6 = a(7) * h3
h1 = h1 + sh.Cells(i + 1, 4) - q1 - q2 - q3
h2 = h2 + q3 - q4 - q5
h3 = h3 + q5 - q6
If h1 < 0 Then
h1 = 0#
End If
If h2 < 0 Then
h2 = 0#
End If
If h3 < 0 Then
h3 = 0#
End If
Next i