Skip to main content
3-Newcomer
December 30, 2022
Solved

Indexing issues

I've written a function C with 2 inputs: a scalar and a vector; and 1 output: a vector. When I evaluate the function for a certain input there is no problem. However, when I try to compute the Jacobian of the function I get the following error: "The array index is invalid. The index must be an integer, not less than ORIGIN, and not greater than the last element."

JV_10456665_0-1672420706772.png

Strangely, when I get rid of the two bottom entries of the output vector of the function C, I get no such error, it produces the Jacobian matrix one would expect it to. This leads me to believe that the issue is in q_3. (I have made sure that 3 is no subscript but an index)

Can anyone tell me what the issue here is?

MichaelWAnswer
17-Peridot
January 3, 2023

Yes, the worksheet would help. Some definitions are obviously done but not visible in the snippet picture.

 

Remember: Some errors thrown are not what they seem to be.

 

From scratch, when I test around with Mathcad Prime 7 (attached), I realize a similar error like in the above picture (index) but caused by a missing definition of q when Jacob() gets called.

 

Remember:

Definition like F(x):= works, even if x is undefined

Call of a function like F(x)= fails if x is undefined

 

Please test if the above is the case in your example:

 

When Jacob function is getting called, and q is not defined, then Mathcad Prime cannot work and mus throw an error.

Test: put a definition of q right prior the call of Jacob() function. Like in this example (first call of Jacob() fails, second works):

MWunder_2-1672735285543.png

Note: of course the values must differ in my example, missing your origin example.

 

 

3 replies

Werner_E
25-Diamond I
December 30, 2022

Can you attach the worksheet? Always better to do so compared to just post a picture.

I guess it could be worth to look at the definitions of the functions x.t and y.t.

Do you get a result if you remove those functions in the definition of function C ?

 

Translate
21-Topaz II
December 31, 2022

Hi,

Translate
MichaelW17-PeridotAnswer
17-Peridot
January 3, 2023

Yes, the worksheet would help. Some definitions are obviously done but not visible in the snippet picture.

 

Remember: Some errors thrown are not what they seem to be.

 

From scratch, when I test around with Mathcad Prime 7 (attached), I realize a similar error like in the above picture (index) but caused by a missing definition of q when Jacob() gets called.

 

Remember:

Definition like F(x):= works, even if x is undefined

Call of a function like F(x)= fails if x is undefined

 

Please test if the above is the case in your example:

 

When Jacob function is getting called, and q is not defined, then Mathcad Prime cannot work and mus throw an error.

Test: put a definition of q right prior the call of Jacob() function. Like in this example (first call of Jacob() fails, second works):

MWunder_2-1672735285543.png

Note: of course the values must differ in my example, missing your origin example.

 

 

Translate