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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Automatically create matrix based on sum of rows and variable in Mathcad

MC_9370533
5-Regular Member

Automatically create matrix based on sum of rows and variable in Mathcad

Hello everyone,

I am trying to automatize a calculation process in Mathcad, but I am having some difficulties doing it.

Lets say I have a matrix with “n x m” number of rows and columns.

In this example we can have the following matrix (5 x 6 – but it can be different, ex: 10 x 15, 9 x 10 etc...):

MC_9370533_0-1653424839493.png

Note that Ni is each row of the matrix.

There is a variable “var” that can be equal to 1, 2, 3 or 4.

And finally we have vector “V” (that has always 1 single column, but number of rows depends on the variable “var” however this vector is an input, the values below are just an example):

MC_9370533_6-1653425383586.png

I want to obtain the following matrix “M” depending on the variable “var”:

- If var = 1 (“V” vector will have just 1 row – F1 = 10)

MC_9370533_2-1653425330437.png

- If var = 2 (“V” vector will have 2 rows – F1 = 10 / F2 = 1)

MC_9370533_3-1653425330443.png

- If var = 3 (“V” vector will have 3 rows – F1 = 10 / F2 = 1 / F3 = 4)

MC_9370533_4-1653425330445.png

 - Finally if var = 4 (“V” vector will have 4 rows – F1 = 10 / F2 = 1 / F3= 4 / F = 7)

MC_9370533_5-1653425330447.png

Any suggestions?

 

Thank you so much for your help,

 

Miguel

ACCEPTED SOLUTION

Accepted Solutions

Good observation, thanks!

Actually the program seems to do the job but for some reason Prime managed to update the creation of the random matrices V and N and using them in the function but did not  update the display of N and V. Actually this should never happen (and never did in MC15 and below).

So a hard recalculation of the worksheet fixes this inconsistency which I had not noticed. Thanks for bringing this to my attention.

I attach a new screenshot in my first reply and also attach the worksheet (even though the OP didn't).

View solution in original post

8 REPLIES 8
Werner_E
25-Diamond I
(To:MC_9370533)

Not sure, but is it this what you are looking for?

Werner_E_0-1653441990664.png

EDIT: Attached a new screenshot as @terryhendicott  had noticed that in the previous one Prime had not displayed the newly created matrices N and V correctly and so the results looked wrong.

Worksheet in P& format attached

Hi

The first row of matrix when v = 1 should be

[18  18  63 ....]

[,,,,              ...]

Cheers

Terry

Good observation, thanks!

Actually the program seems to do the job but for some reason Prime managed to update the creation of the random matrices V and N and using them in the function but did not  update the display of N and V. Actually this should never happen (and never did in MC15 and below).

So a hard recalculation of the worksheet fixes this inconsistency which I had not noticed. Thanks for bringing this to my attention.

I attach a new screenshot in my first reply and also attach the worksheet (even though the OP didn't).

MC_9370533
5-Regular Member
(To:Werner_E)

Hello Werner_E,

Yes it's exactly this I was looking for.

 

Thank you so much for your help.

 

(Also Terry thank you for your feedback).

 

Miguel,

LucMeekes
23-Emerald III
(To:MC_9370533)

So you want to create a specific matrix, namely a vector, from a matrix, a vector and a variable.

If the matrix is this:

LucMeekes_0-1653460924838.png

The vector is this:

LucMeekes_1-1653460944843.png

and the variable is 1 you want:

LucMeekes_2-1653460965173.png

if the variable is 2 you want:

LucMeekes_3-1653460986688.png

on to, if it is 4 you want:

LucMeekes_4-1653461050097.png

That can be easily accomplished by this simple function that also works in Prime express:

LucMeekes_5-1653461084541.png

A numeric example:

LucMeekes_6-1653461114786.pngLucMeekes_7-1653461119305.png

LucMeekes_10-1653461168467.png

LucMeekes_11-1653461196933.png

 

LucMeekes_9-1653461140477.png

Prime 4 file is attached.

 

Success!
Luc

 

 

 

MC_9370533
5-Regular Member
(To:LucMeekes)

Hello Luc,

 

I was looking for a solution proposed by Werner_E.

 

Either way thank you for your feedback.

 

Miguel,

LucMeekes
23-Emerald III
(To:MC_9370533)

Ah, I see where I went wrong. A small correction is needed:

LucMeekes_0-1653467858148.png

Now gives:

LucMeekes_1-1653467875211.png

and

LucMeekes_2-1653467891050.png

Which meets your description in the original post.

I understand that that description apparently does not match with what you intended...

 

Luc

LucMeekes
23-Emerald III
(To:MC_9370533)

However, if your vector V always has the length of the value of the variable var, then you don't specifically need var, and the function can become simpler:

LucMeekes_16-1653462082240.png

And you get:

LucMeekes_13-1653461791000.png

LucMeekes_14-1653461797922.png

LucMeekes_15-1653461805338.png

Prime 4 file attached (You may need to force recalculation of the sheet, to update the symbolic results).

 

Success!
Luc

Announcements

Top Tags