Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- array index invalid

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-06-2021
10:59 AM

05-06-2021
10:59 AM

Hi,

I'm trying to replicate a template that evaluates the shear and moment of a simple beam. The problem is that to W array, I've got the message that n is invalid. The index should be an integer that it is n=3, no less than origin that it is because i have set up origin=1 and no greater than the last element which i don't know if is true. Any idea how can I fix it?

Thanks

Thank you all for taking the time. It was the origin :1 that was not written as it should so no all sorted.

Thank you very much anyway!!

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-06-2021
11:44 AM

05-06-2021
11:44 AM

Hi Luc,

thanks for the reply. I have set the origin to 1 at the first row. The thing is that n=3 and not 2. That will give me the right result. As I've mentioned I'm just replicating a template that makes sense so at the end VL- should be a 3x1 vector and changing this value doesn't give me the right result. I'm attaching the template to see the results that I should have. I understand that it is 3>2 that's the issue but how could I write it differently to return the values as per the template?

Thanks,

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-06-2021
11:10 AM

05-06-2021
11:10 AM

Re: array index invalid

Please attach the Prime worksheet. (You should ALWAYS do that.)

Apart from that:

Your Pn:= if(....

works, because the length of p (=2) is less than that of a (=3)

Your Wn:=if(...

throws an error because the length of w (=3) is NOT less than that of a (=3). Therefor the if tries to execute the 'else' statement, accessing p.n. with n=3. You probably missed that (by default) ORIGIN=0, which means that arrays are indexed starting at 0, not at 1, p.3 doesn't exist, the last element of p is p.2.

That makes W undefined.

Instead of n:=rows(a)

set n:=last(a)

Then n will become 2 and these errors disappear.

Leaves you with one more error at the end (actually 2, read on...). You have defined an M.L at the top, in the end you use M[L. Those are different. The first is a literal subscript (the result of typing M[CTL _]L ), the other is an array subscript (the result of typing M[L ) which requires the vector M to exist.... it doesn't. The error for M[R isn't flagged yet, Prime flags only one error per expression...

Success!

Luc

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-06-2021
11:14 AM

05-06-2021
11:14 AM

Re: array index invalid

Hi,

Please see attached.

Cheers,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-06-2021
11:44 AM

05-06-2021
11:44 AM

Hi Luc,

thanks for the reply. I have set the origin to 1 at the first row. The thing is that n=3 and not 2. That will give me the right result. As I've mentioned I'm just replicating a template that makes sense so at the end VL- should be a 3x1 vector and changing this value doesn't give me the right result. I'm attaching the template to see the results that I should have. I understand that it is 3>2 that's the issue but how could I write it differently to return the values as per the template?

Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-06-2021
11:14 AM

05-06-2021
11:14 AM

Re: array index invalid

It looks like you've defined "w" as a matrix and not a vector (array). Prime is looking for a 2-dimension assignment/callout.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-06-2021
11:27 AM

05-06-2021
11:27 AM

Re: array index invalid

No, w is defined as a vector, due to the transpose operator.

Luc

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

05-06-2021
01:18 PM

05-06-2021
01:18 PM

Re: array index invalid

Ah yes, noted...my quick trial left out the transpose operator...