[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Short Cut Way to Assign the Variables x1, x2....x40 names

From: Fausto Arinos de A. Barbuto
Subject: Re: Short Cut Way to Assign the Variables x1, x2....x40 names
Date: Sun, 14 Sep 2014 19:25:28 -0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.1

On 13-09-2014 15:43, Ed Song wrote:

I have a 40 period model and want to assign the variable x1, x2...x40 names 
without having to
write the same subroutine 40 times. I remember in Fortran and Pascal we use to 
assign the
variable x an index i, hence xi. Then use a Do Loop to calculate x1 through x40 
without having
to write out the routine 40 times. I'm trying to make heads or tails out of the 
manual, but am
having a difficult time. Is there a w ay I can make the calculation 40 times 
doing the routine
once instead of 40 times?

For example, suppose x1 = y1 + a, and x2 = y2 + a...x40=y40+a

In Fortran we would write a program something like this:

Do i=1,40

In Fortran, the two statements above would sum the scalar "a" to the *scalar* 
"yi" 40 times,
assigning the result to the *scalar* xi the same 40 times.  And whichever the values of 
or "yi", "xi" would always have the same value in the end, be "i" either 1, 2, 
..., 40,
whatever. Doesn't make a whole lot of sense.  What you perhaps meant is:

Do i = 1, 40
   x(i) = y(i) + a
End Do

Be aware though that, for example, x(1) = y(1) + a is not the same as x1 = y1 + 
x(1) and y(1) are members of an array, whereas x1 and y1 are scalars.  
Therefore, what
you suggested can't be done in Fortran.

In the following program I didn't have to write out x2=y2+a, x3=y3+a...etc.

Is there a similar procedure in Gnu Octave? How would I write an equivalent 
program to the above
in Gnu Octave?


Help-octave mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]