|
-
cant add 3 variables with diff array inside for loop
i m trying to convert one Vb code to jscript code.
but i stack in for loop operation and the result not comming same after implimentation.
VB code here:
Code:
Function h1_pT(ByVal p As Double, ByVal T As Double) As Double
Dim i As Integer
Dim ps, tau, g_t As Double
Dim I1, J1, n1 As Variant
Const R As Double = 0.461526
I1 = Array(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 8, 8, 21, 23, 29, 30, 31, 32)
J1 = Array(-2, -1, 0, 1, 2, 3, 4, 5, -9, -7, -1, 0, 1, 3, -3, 0, 1, 3, 17, -4, 0, 6, -5, -2, 10, -8, -11, -6, -29, -31, -38, -39, -40, -41)
n1 = Array(0.14632971213167, -0.84548187169114, -3.756360367204, 3.3855169168385, -0.95791963387872, 0.15772038513228, -0.016616417199501, 8.1214629983568E-04, 2.8319080123804E-04, -6.0706301565874E-04, -0.018990068218419, -0.032529748770505, -0.021841717175414, -5.283835796993E-05, -4.7184321073267E-04, -3.0001780793026E-04, 4.7661393906987E-05, -4.4141845330846E-06, -7.2694996297594E-16, -3.1679644845054E-05, -2.8270797985312E-06, -8.5205128120103E-10, -2.2425281908E-06, -6.5171222895601E-07, -1.4341729937924E-13, -4.0516996860117E-07, -1.2734301741641E-09, -1.7424871230634E-10, -6.8762131295531E-19, 1.4478307828521E-20, 2.6335781662795E-23, -1.1947622640071E-23, 1.8228094581404E-24, -9.3537087292458E-26)
p = p / 16.53
tau = 1386 / T
g_t = 0#
For i = 0 To 33
g_t = g_t + (n1(i) * (7.1 - p) ^ I1(i) * J1(i) * (tau - 1.222) ^ (J1(i) - 1))
Next i
h1_pT = R * T * tau * g_t
End Function
and my jscript code here:
Code:
var h1_pT;
function h1_pT(){
var R = 0.461526;
var T = 106+273.15;
var p = 3/10;
var tau = 1386 / T;
var I1 = new Array (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 8, 8, 21, 23, 29, 30, 31, 32);
var J1 = new Array (-2, -1, 0, 1, 2, 3, 4, 5, -9, -7, -1, 0, 1, 3, -3, 0, 1, 3, 17, -4, 0, 6, -5, -2, 10, -8, -11, -6, -29, -31, -38, -39, -40, -41);
var n1 = new Array (0.14632971213167, -0.84548187169114, -3.756360367204, 3.3855169168385, -0.95791963387872, 0.15772038513228, -0.016616417199501, 8.1214629983568E-04, 2.8319080123804E-04, -6.0706301565874E-04, -0.018990068218419, -0.032529748770505, -0.021841717175414, -5.283835796993E-05, -4.7184321073267E-04, -3.0001780793026E-04, 4.7661393906987E-05, -4.4141845330846E-06, -7.2694996297594E-16, -3.1679644845054E-05, -2.8270797985312E-06, -8.5205128120103E-10, -2.2425281908E-06, -6.5171222895601E-07, -1.4341729937924E-13, -4.0516996860117E-07, -1.2734301741641E-09, -1.7424871230634E-10, -6.8762131295531E-19, 1.4478307828521E-20, 2.6335781662795E-23, -1.1947622640071E-23, 1.8228094581404E-24, -9.3537087292458E-26);
var p1 = p / 16.53;
var g_t = 0;
for (i=0;i<33;i++){
g_t = g_t + (n1[i] * (7.1 - p1) ^ I1[i] * J1[i] * (tau - 1.222) ^ (J1[i] - 1));
}
h1_pT = R * 1386 * g_t; // here T * tau = 1386
document.getElementById("max1").innerHTML = h1_pT;
}
timer=setInterval('h1_pT()',1000);
here input value p and T (in VB if p =3 then Jscript its 3/10 for T if Vb its 106 then in jscript 106+273.15 ) i m sure for those input value.
but the output comming in jscript is 9119395 where actual output in vb is only 444.
in vb code for code is:
Code:
For i = 0 To 33
g_t = g_t + (n1(i) * (7.1 - p) ^ I1(i) * J1(i) * (tau - 1.222) ^ (J1(i) - 1))
and my code is:
Code:
var g_t = 0;
for (i=0;i<33;i++){
g_t = g_t + (n1[i] * (7.1 - p1) ^ I1[i] * J1[i] * (tau - 1.222) ^ (J1[i] - 1));
}
i think this for loops is making some problem while calculating and need to adjust.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
|
Bookmarks