Trouble Replicating a Do Loop Structure

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
pwr
Posts: 13
Joined: Thu Apr 16, 2009 8:37 pm

Trouble Replicating a Do Loop Structure

Post by pwr » Sat Jun 06, 2009 3:08 am

I am trying to convert an existing program and have the following Revolution function.

function s1_pT p, T
--
--Release on the IAPWS Industrial formulation 1997 for the Thermodynamic Properties of Water and Steam, September 1997
--5 Equations for Region 1, Section. 5.1 Basic Equation
--Eqution 7, Table 3, Page 6
--
put 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 into I1
put -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 into J1
put 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 into n1
put 0.461526 into R --kJ/(kg K)
put p / 16.53 into myPi
put 1386 / T into tau
put 0 into gamma
put 0 into gamma_der_tau
repeat with i = 1 to 34
put gamma_der_tau + (n1 * (7.1 - myPi) ^ I1 * J1 * (tau - 1.222) ^ (J1 - 1)) into gamma_der_tau
put gamma + n1 * (7.1 - myPi) ^ I1 * (tau - 1.222) ^ J1 into gamma
end repeat
put R * tau * gamma_der_tau - R * gamma into s1_pT
return s1_pT
end s1_pT


The problem I'm seeing is that the variables gamma and gamma-der_tau never change from the initialized zero value.

Can anyone tell me why? Is there a problem with my use of the 'repeat' control structure, or is the problem with the way I've initialized my arrays? Is the first array index 0 or 1? Something else????

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Post by WaltBrown » Sat Jun 06, 2009 3:13 am

Try
add (n1 * (7.1 - myPi) ^ I1 * J1 * (tau - 1.222) ^ (J1 - 1)) to gamma_der_tau
add (n1 * (7.1 - myPi) ^ I1 * (tau - 1.222) ^ J1) to gamma

Walt
Walt Brown
Omnis traductor traditor

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Sat Jun 06, 2009 7:58 am

The problem is that you're loading the data into a variable and then treating it like an array. To convert the variable lists to arrays, insert the following statements before the repeat loop:

Code: Select all

    split n1 by comma
    split I1 by comma
    split J1 by comma
(also, you'll probably confuse the compiler at some point if you define your return value name the same as your function name. You have to do this in Basic, and I assume that the original source is Basic for this reason, but it's better practice anywhere else to call your return value tReturn or something similar...)

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sat Jun 06, 2009 10:59 am

pwr,
alternatively you could stick to the comma delimited item list you created (you did not create an array as Mark said) in the variables by changing your repeat loop:

Code: Select all

 repeat with i = 1 to 34
    put (item i of I1) * (item i of J1) into and so on
 end repeat
regards
Bernd

edited: previous version said variable where it should have said array

Post Reply