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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Issue: This array index is invalid for this array

zchin
1-Visitor

Issue: This array index is invalid for this array

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 

10 REPLIES 10

Sorry, but H is a vector, not a matrix

H1.png

Hi,

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

How to convert this to be a matrix?

Fred_Kohlhepp
23-Emerald I
(To:zchin)

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.

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..

Fred_Kohlhepp
23-Emerald I
(To:zchin)

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!

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!

Fred_Kohlhepp
23-Emerald I
(To:zchin)

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.

Hi,

I am using Mathcad 15, but failed to open first file.

I am new to Mathcad. I read through the Mathcad user guide before I started this.

I don't quite get what you said that "I need to set up H and V as arrays (with I rows and j columns)"

Didn't i set H and V up with i and j? or i set them wrongly?

The excerption that you showed above is rather confusing, I do have a hard time to understand them.

I thought matched is not more complicated than other C programming software..

Anyway, let me explore more. Hope I could complete this assignment before due.

Thanks for your effort to explain, even though I don't get most of them.

Fred_Kohlhepp
23-Emerald I
(To:zchin)

Attached is an example.  I've created two arrays H and V,  5001 rows by 1001 columns.  And I've created one of your cost functions and a solve block for it.  It won't solve (and the error message doesn't mean what it says.)  I don't have enough constraints for the system to solve--I can't say what the start and end conditions need to be.

Good luck with this; it seems to me there are things missing (or I don't understand.)

I couldn't see the attachment in your reply.

I think the formula that i set was correct, there might be some missing constraints as you said..

The initial condition is per what i mentioned earlier:

initial value at 0 time step.JPG

Probably i need to set a constraint when i=0 and i=final point (i.e. 5000m).

Announcements

Top Tags