Skip to main content
1-Visitor
October 18, 2015
Question

Issue: This array index is invalid for this array

  • October 18, 2015
  • 3 replies
  • 5671 views

Hi all,

I recently encounter an issue while writing my algorithm and have no clue how to resolve it. Can anyone here help me out?

Please see the attached Algorithm.

Appreciate if anyone here could advise. Thanks in advance.

Cheers,

ZQ 

3 replies

24-Ruby IV
October 19, 2015

Sorry, but H is a vector, not a matrix

H1.png

zchin1-VisitorAuthor
1-Visitor
October 19, 2015

Hi,

Does it mean i can't use i,j to represent a vector?

How to convert this to be a matrix?

23-Emerald I
October 19, 2015

What are you attempting to solve for?  The velocity profile along the pipe?

Please notice that your equation for H is a constant value, does not depend on I.

Your equations are cost functions for V.  Properly expressed they can be used in a solve block to obtain your answer.

zchin1-VisitorAuthor
1-Visitor
October 19, 2015

Hi,

I am doing this to solve for pressure head (H) and velocity (V) at various location and different time step. X axis (represented by i value) is the location, Y axis (represented by j value) is the time step.

i made a mistaka, H shall vary with i value, i.e.

Hi,j = 119.3m – [(119.3m-112.5m)*(i*Δx/5000m)]

i have corrected it, but same error comes out: This array index is invalid for this array..

23-Emerald I
October 19, 2015

Attached is an example of a finite difference solution to a differential equation.  You develop vectors for the parameters you are solving for, and assign guess values.  (You need a vector of X (nodes along your pipe), and Vectors for H and V that specify values at each node.  (starting guesses are not terribly critical, they can be constant values in all cells.)  You then create a cost function (basically your "C" algorithms) that define the relationships.  A solve block is used to find the values that solve the cost function.  The solution then plots the vector values along the nodes.

As for "invalid indices:

  • A vector needs only one index, so H sub i,j has one too many indices.
  • By default Mathcad starts indices at 0.  You may change this with the built-in variable "ORIGIN"

Good luck!

zchin1-VisitorAuthor
1-Visitor
October 20, 2015

Hi,

I failed to open the first file.

However, i saw the second file which you changed the original equation to Cost function. May i know if Cost carry any special meaning?

Is it possible to add in both i and j in Cost function? i and j are equally important in solving this set of equations, where i represents the point of interest and j represents the time step (the response of H and V over a period of time).

Initial values at 0 time step (j=0) shall be defined as:

initial value at 0 time step.JPG

whereby Velocity (V) at 0 time step (j=0) will be constant along the pipeline (i=1,2.. 5000); Pressure Head (H) will reduce proportionally from the starting point to end point (i=1,2.. 5000) at 0 time step (j=0).

Is there any way we can discuss this in a more efficient manner? via skype or some other ways?

I am really keen to learn more about Mathcad, if you're convenient to share your knowledge.

Truly appreciate if you could help. Thanks in advance!

23-Emerald I
October 20, 2015

Ziqin Chin wrote:

Hi,

I failed to open the first file.

Both files are version 15.

Ziqin Chin wrote:

Hi,

Is it possible to add in both i and j in Cost function? i and j are equally important in solving this set of equations, where i represents the point of interest and j represents the time step (the response of H and V over a period of time).

Initial values at 0 time step (j=0) shall be defined as:

initial value at 0 time step.JPG

whereby Velocity (V) at 0 time step (j=0) will be constant along the pipeline (i=1,2.. 5000); Pressure Head (H) will reduce proportionally from the starting point to end point (i=1,2.. 5000) at 0 time step (j=0).

If you want to use j as a time index you need to set it up that way.  You need to set up H and V as arrays (with I rows and j columns) then write your cost functions as functions of arrays H and V and indices I and j.

Excerpted from the file you couldn't open:

The Given/Find construct is a "solve block."  Mathcad will (if things go well) find the values of Y that satisfy the constraints.  (Go read the help for solve blocks.)

This is a challenging problem.  Might be a good idea to explore some of the examples in the help files to understand better what you're trying to do.

Mathcad can also solve differential equations; you might want to explore that.