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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Calculating multiple matrices in a loop

CharlesChan
1-Newbie

Calculating multiple matrices in a loop

Normally, we work with a matric which is a 2D element. (with rows and columns A i,j). However, if I were to work with generation of a few matrices in a loop, I would need another index to preserve the matrices, so that I can return a 'set' of matrices in the operation. How would someone approach this problem to return a set of matrices and hence 3D matrices in a loop or 4D matrices in 2 sets of loops?

I did a search and found a previous discussion on it.

http://communities.ptc.com/message/46160#46160

However, when I tried this approach, I am not having any success on it. Maybe I didn't put in with the right syntax? Attached is the file. Please provide any assistance or suggestion if you can. Thanks in advance.

Regards,

Charles Chan

1 ACCEPTED SOLUTION

Accepted Solutions

A few brief notes in the attached...

~R~

View solution in original post

11 REPLIES 11
MikeArmstrong
5-Regular Member
(To:CharlesChan)

Something like the attached?

You didn't define i,j or k.

Mike

Mathcad doesn't directly support true multi-dimensional array (MDA) indexing, so the forms you've used (Ai,j,k) are invalid.

I'm afraid that you'll have to go through the kind of process you've used to create the nested matrices; I'd probably opt for writing a function to process a single array and then call that from within the loop.

You might want to look at this thread http://communities.ptc.com/message/132423#132423 . There are a couple of messages in that reference an MDA library that I wrote (just to show it could be done relatively easily) - it's generally compatible with the way Matlab does things.

Stuart

A few brief notes in the attached...

~R~

Hi,

I would like to all of you for the valuable input that I have received concerning this thread. My main goal was to have an automated program to go thru a loop "n" times to produce a set of "n" matrices based on the variable n. I was mainly interested in displaying the individual matrices M within the loop for checking purposes and to use them for further computation.

I spent some time trying out the programming in an attempt to get it working but without success for a while. Then I decided to try it using the Mathcad 14 version. I have the Mathcad 2001 version at home but have the Mathcad 14 at work. I do some programming at work and also do a lot of programming at home. Therefore, I usually default to the lower version because then it will be compatible both at home and at work, and whenever I started a program at work I can also continue working on it when I get home.

I moved the program to Mathcad 14 and found that I was finally able to get almost all of what I want working. However, I was not able to get the '3D" matrix A to displace with the individual sets of matrices using the equal sign after the logic routine. I was only able to obtain A = ({5,3},{5,3},{5,3},{5,3}).

Rich, can you please advise me as how you were able to obtain a display of the sets of matrices after A using the equal sign? I was able to display the individual matrices separately in a loop but not together within the definition of A. So for now it will suffice, but I am curious as to how one may be able to obtain the A = ( "sets of matrices on display") from the file that you sent me. Is there anything that I need to do after typing in A following the routine other than using the equal sign from the keyboard or did you use something else to get it to display?

Attached are two of my files for review. Thank you to all of you who have comtributed to this thread.

Regards,

Charles Chan

Charles Chan wrote:

I moved the program to Mathcad 14 and found that I was finally able to get almost all of what I want working. However, I was not able to get the '3D" matrix A to displace with the individual sets of matrices using the equal sign after the logic routine. I was only able to obtain A = ({5,3},{5,3},{5,3},{5,3}).

Select A = ({5,3},{5,3},{5,3},{5,3}), then go to Format/Result/Display oprions and check Expand nested arrays.

Alan

Thanks for replying, Alan. This is a busy time for me. Not much time for a real visit; just enough sometimes for a drive-by comment...

~R~

Thanks Alan for the simple solution to my problem. I am still new to using matrices on Mathcad. I appreciate your help.

Regards,

Charles

Hi all,

Here is a follow up on working with multiple matrices in a loop. I have a set of n matrices that I would like to 'convert' into another set of matrices using a mapping function which will determine the locations of the elements of the original matrices.

I found that I was able to accomplish it manually by doing the mapping routine one by one, matrix by matrix. However, when I tried to accomplish it in a loop to cycle thru 'n' matrices, it does not work. This goes back to the concept of working with matrices in a loop that I posted earlier. Anyone has any idea how it can be accomplished? Did I do anything work with my syntax? Please advise and thank you in advance.

Regards,

Charles Chan

Charles Chan wrote:

Hi all,

Here is a follow up on working with multiple matrices in a loop. I have a set of n matrices that I would like to 'convert' into another set of matrices using a mapping function which will determine the locations of the elements of the original matrices.

I found that I was able to accomplish it manually by doing the mapping routine one by one, matrix by matrix. However, when I tried to accomplish it in a loop to cycle thru 'n' matrices, it does not work. This goes back to the concept of working with matrices in a loop that I posted earlier. Anyone has any idea how it can be accomplished? Did I do anything work with my syntax? Please advise and thank you in advance.

You probably need to use a program in preference to range variables, and you might be better of creating a mapping function that applies to a whole array.

See attached for one possibility.

Stuart

Hi Stuart,

Thank you for the insight and valuable information on the looping routine with matrices and the suggestion of the application of using a function to perform the mapping.

By the way, your earlier link to a thread on the discussion of using MDA is broken. Can you attach the routine for my edification? Thank you very much.

Charles

Thank you for the insight and valuable information on the looping routine with matrices and the suggestion of the application of using a function to perform the mapping.

No worries.

By the way, your earlier link to a thread on the discussion of using MDA is broken. Can you attach the routine for my edification? Thank you very much.

One of those web oddities, I guess, as they seem to work for me (IE6 running on WinXP).

However,

Top Tags