cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

1-Newbie

Using a range variable to repeat the same calc many times

The code that I am working with is shown below.

I want to eventually make the matrix for the variable "Reactions(Conc)", extremely large (~1400 rows, 1 column), but I'm working with only 2 rows for now to learn how to code in the array mathematics. The calcs below are working fine, and are reporting the correct answers, but I don't want to type the Greek capital PI and the arguements for it 1400 times, so I'm trying to use the range variable i2 in place of the 0 and the 1 in the first and second rows of "Reactions(Conc)", and then I want to only enter the capital PI statement once, and just have the range variable repeat it for all ~1400 rows. This isn't working for me though. When I sub in the i2 where the 0 or 1 numbers are right no, it does not continue to give me the nice 1 X 2 matrix with the Conc variables that is shown here. It just shows up in red, doesn't symbolically evaluate it, and says "pattern match exception." Is there a different way to use this range variable so that it will take care of repeating the rows of "Reactions(Conc)" for me?

5 REPLIES 5
24-Ruby I
(To:ptc-3031221)

I think it will be better use programming tool (the for loop) for this task.

21-Topaz I
(To:ptc-3031221)

You can't really use an externally defined range variable inside a function definition (a type of program).

A range variable simply holds the range itself (ie, a,b..c). The main worksheet itself sees a range variable as an instruction to iterate over the range definition's expansion. A program, however, sees it simply as the value 'a,b..c', which is not a number and, therefore, use it as an exponent. However, a function (or program) can deal with it in a for loop, as can be seen from the example at the top of the attached worksheet. It's usually good programming practice to pass a range variable as an argument rather than as global, so I've shown two alternative choices for dealing with what I think(?) may be your need, and I'd recommend using the latter.

Stuart

PS. Is there some particular reason you want to use the symbolics? If not, then I'd probably stick to the standard numerics.

1-Newbie
(To:StuartBruff)

Thanks for the advice. The reason why I'm using symbolics is because I'm using these lines of code to generate a long list of equations that I'm going to feed into a differential equation solver. This is going to work now!

15-Moonstone
(To:ptc-3031221)

Perhaps you're looking for something like this:

Alan

1-Newbie
(To:AlanStevens)

That code works for me. Thanks for your help!

Announcements
Check out the latest