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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

For Loop function in nested matrix/vector

StrucEngr
4-Participant

For Loop function in nested matrix/vector

Attempting to do basic "For Loop" program on a nested matrix/vector using Mathcad prime 4.0. As you can see below the right "test" program snippet is displaying an error.The error message I get is reads "This operation can only be performed on an array". The left "test" program snippet is performing the evaluation when the "k" counter is omitted from "chk" variable. In this case returning result for "k" = 4. I was anticipating right "test" program snippet returns a [4x1] matrix or vector after evaluating for each "k" value.

 

Would someone help with an insight on how to resolve this issue?

 

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:StrucEngr)

Essentially you attempting to create a nested array from scratch. That does not work in this way.

You can create an array, or a matrix, from scratch using a for loop, but to create a nested array (or matrix) you first have to create the element before you can put it into the array.

 

Attached is an explanation (Prime 4).

 

Success!
Luc

View solution in original post

21 REPLIES 21
LucMeekes
23-Emerald III
(To:StrucEngr)

Please attach your prime worksheet.

Look in the 'Anouncement' to the right of this column, below the advertorial picture, for tips on attaching.

 

Success!
Luc

StrucEngr
4-Participant
(To:LucMeekes)

Luc,

See attached. This Mathcad prime file is not identical to the PNG file I posted earlier, but has the same kind of issue.

LucMeekes
23-Emerald III
(To:StrucEngr)

Essentially you attempting to create a nested array from scratch. That does not work in this way.

You can create an array, or a matrix, from scratch using a for loop, but to create a nested array (or matrix) you first have to create the element before you can put it into the array.

 

Attached is an explanation (Prime 4).

 

Success!
Luc

StrucEngr
4-Participant
(To:LucMeekes)

Luc,

Thank you for the help and providing an explanation w/ example!

AdriCreu
4-Participant
(To:StrucEngr)

Hi,

 

Can you tell me what is wrong with this please:

Essai.pngThis is a very simple routine!

 

Thanks

AdriCreu
4-Participant
(To:AdriCreu)

Got the answer sorry.

It's because in my routine i is just an indice… Such a time wasted for this stupid mistake^^

Werner_E
25-Diamond I
(To:AdriCreu)


@AdriCreu wrote:

Got the answer sorry.

It's because in my routine i is just an indice… Such a time wasted for this stupid mistake^^


It also has its good - its very unlikely you will confuse Mathcads two types of indices in future worksheet - you will remember.

Its very common to confuse literal indices and vector indices.

yhuang-8
6-Contributor
(To:LucMeekes)

Hi Luc,

 

I am quite new to mathcad. I have the same question and believe your scripts gonna help. But after I opened it, it is blank. Is it because I am still using prime 2? Thanks!

MJG
18-Opal
18-Opal
(To:yhuang-8)

Here's a snapshot of Luc's worksheet for reference:

Capture.PNG

yhuang-8
6-Contributor
(To:MJG)

Thank you so much!

BTW you have any idea that why it is blank when I opened it in prime 2?

 

MJG
18-Opal
18-Opal
(To:yhuang-8)

If you open in any version prior to Prime 4.0, you should get the following error:

Capture.PNG

Prime then opens a blank worksheet for your use, but it is not attempting to open the specified file.

PTC has decided that files should not be backwards compatible, so older versions cannot open files form newer versions, and newer versions cannot even save-as to an older version.

yhuang-8
6-Contributor
(To:MJG)

ok thanks!

In Prime, like many other products, early versions (2.0) cannot read later versions (3.0, 3.1, 4.0).

 

In Prime, unlike other products, later versions (4.0) cannot write earlier versions (3.1, 3.0, 2.0). 

 

When you tried to open the file it failed, and Prime 2.0 opened a new blank worksheet.

thanks!

it would probably better for me to ask you a question directly here on converting a nested matrix to a clean one. I am dealing with the nested matrix in the attachment. Right now what I am doing is to match the row of the clean one with the nested. But since later the number of rows gonna be crazy, and I do not think I want to do the same thing. I tried using the loop but had a hard time with the index. Wonder if there is some reference I can look at. Thanks!

Can you post your Prime file?  If you have 2.0, people with newer versions can open it. 

 

Your picture does not explain the problem; from that picture you have a vector p3 (one subscript says only a single column), where at least one element is a six row by four column array where each array is a 101 element column vector.

 

There is no information about what you want to match. . .

yhuang-8
6-Contributor
(To:Werner_E)

Hi Werner_E,

I figured out it would be better to redefine the nested matrix instead of converting them to a 707*4 matrix. 

As shown in the following link, 

https://community.ptc.com/t5/PTC-Mathcad-Questions/For-Loop-function-in-nested-matrix-vector/td-p/548645,

Luc suggested that we cannot create a nested matrix from scratch. I tried to create the element before I put it in but still did not work (please see attachment). Mine is a little bit complicated than Luc's example, since it involves multiply nested matrix and I do not want to redefine them one by one. 

Thanks! 

yhuang-8
6-Contributor
(To:Werner_E)

Please ignore my last question. I already figured it out. And thanks!

yhuang-8
6-Contributor
(To:LucMeekes)

Hi Luc,

You suggested that we cannot create a nested matrix from scratch. I tried to create the element before I put it in but still did not work (please see attachment). Mine is a little bit complicated than Luc's example, since it involves multiply nested matrix and I do not want to redefine them one by one. 

Thanks! 

yhuang-8
6-Contributor
(To:LucMeekes)

Please ignore my last question. I already got it figured out. thanks!

Announcements

Top Tags