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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Adding Additional Rows to an Existing Matrix in MathCAD Prime 8 Using Formulas Based on Exist Matrix

Perez
14-Alexandrite

Adding Additional Rows to an Existing Matrix in MathCAD Prime 8 Using Formulas Based on Exist Matrix

Hello everyone,

 

I have a new question for you that should be straightforward. I'm wondering how write a program to add additional rows to a matrix, where the values of the elements are calculated according to a formula using existing data within the matrix.

 

The attached Excel file includes a tab with input for the ReadExcel function, as well as a tab showing the desired output by a writexcel function. Essentially, the matrix is a list of node point IDs with force vectors due to six load cases. Each node ID will have the same number of load cases and the input will be always sorted by LoadCase column. I would like to add new rows for each node ID, namely 7 OPEPOS and 8 OPENEG, using a specific formula which pulls its input from the existing data within the matrix.

 

Input for the readexcel function:

EP_10515634_0-1687468714739.png

Desired output by the writexcel function:

EP_10515634_1-1687468830733.png

Rows 8, 9, 16 and 17 should be added by the formulas:

EP_10515634_2-1687468939877.png

EP_10515634_3-1687468972325.png

FR is the force resultant.

Just as a note, I have currently MathCAD Prime 8 and unfortunately I don't have access to p9.

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:LucMeekes)

Thanks, I had overlooked the @Perez  had already stated the used version in the subject.

View solution in original post

7 REPLIES 7
LucMeekes
23-Emerald III
(To:Perez)

My first approach would be to read the data from your excel sheet into a matrix in Prime. Then add the rows to the end of the matrix. Then sort the matrix (columns A and F might make a nice couple) then write out the resulting matrix to excel..

But I'm not going to do the work for you, certainly not without your Prime worksheet. (Any version of Prime will do. )

You start!

 

Success!
Luc

Perez
14-Alexandrite
(To:LucMeekes)

Hello LucMeekes,

I started with the program as suggested and my Prime worksheet is attached as well as the raw excel data for the input.

Please disregard the previous excel input file and work with the attached excel file "Input and Desired Output v2.xlsx".

I was able to read the raw data and then sort the matrix in groups of NodeIDs. 

I can take it from this:

EP_10515634_0-1687573520265.png

To this:

EP_10515634_1-1687573567853.png

Where I need the help is to insert two rows for each group with the calculation of OPEPOS and OPENEG for FX, FY and FZ columns.

FR is the resultant force calculated by the square root of the squares (FX^2+FY^2+FZ^2)^1/2.

The desired output should be like this:

EP_10515634_2-1687573847129.png

The formulas for OPEPOS and OPENEG are in the MathCAD worksheet so you don't need to type them from scratch.

EP_10515634_3-1687574007440.png

EP_10515634_5-1687574321800.png

Thanks in advance for the support.

 

 

Werner_E
25-Diamond I
(To:Perez)

Here are my 2 cents, but I used your original Excel input file.

The solution is unlikely to win a contest for beauty and elegance, but so what ...

 

To use the new unsorted Excel Input file, you would first have it to sort for column F and then for column A.

You may do it in Prime, too, but you have to take care because the built-in "sort" function would not leave the order of the sorted column F intact when you sort for column A.
There were posted sort functions here quite a while ago which would do so, though.

But you may also use the grouped record you already created and stack them so you get the needed single matrix.

 

You may also use a command like the following

Werner_E_0-1687577122149.png

But I just notice that your new Excel file is missing some of the columns which were present in the first one you posted, so you would have to change my ProcessData( ) function accordingly - guess you will see where changes are needed.

 

 

Attached file is in format Prime 9

LucMeekes
23-Emerald III
(To:Perez)

Here is Werner's file in Prime 8.

 

Success!

Luc

Werner_E
25-Diamond I
(To:LucMeekes)

Thanks, I had overlooked the @Perez  had already stated the used version in the subject.

Perez
14-Alexandrite
(To:Werner_E)

Hello @Werner_E and @LucMeekes 

 

The program worked.

 

I had to adjust the number of columns for the submatrix when reading the Input (from cols(Input)-1 to cols(Input) )and then I created the header and finally made the Data:=stack(header,data) before passing it to ProcessData(Data).

 

The newData matches the desired output. I also tested it by adding another group of nodes with the same six load cases. I will expand the program for more load cases that will be input for other formulas. If I run into some issues, I'll let you know.

 

EP_10515634_4-1687630455464.png

 

EP_10515634_3-1687630403739.png

 

EP_10515634_0-1687630060229.png

 

EP_10515634_1-1687630083564.png

 

EP_10515634_2-1687630111788.png

Also, just for my understanding, please explain me what happens here:

 

EP_10515634_5-1687630915125.png

 

Werner_E
25-Diamond I
(To:Perez)


Also, just for my understanding, please explain me what happens here:

 

EP_10515634_5-1687630915125.png

 


You may have noticed that the algorithm used for "csort" does not preserve the order of the rows with the same "Area" letter when you first sort the matrix for the "LoadCase" column and then for the "Area column". There are algorithms which do preserve the order, but the built-in doesn't.

One way to cope with that problem is seen in the picture. The concat command creates strings by concatenating the Area letter and the LoadCase. So something like "A1 GR" or "B4 T3" is created. Because I want to concat the whole vectors I had to vectorize (the arrow over the expression) the command.

This new column is put in front of the data matrix via the augment function and this new matrix is now sorted for this first column. This creates the order we need - primary key "Area" column and secondary key "LoadCase" column.

After sorting the first column is removed using the submatrix command. It may be a little bit shorter if the first column is removed using the trim command.

data:=trim(csort(augment(concat(....)) ^T,0)^T

should work as well (^T denotes matrix transposition which is necessary because trim will only remove rows)

Announcements

Top Tags