Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hi,
I have an issue where I have a 5x7 Matrix that I would like to divide each element with the correlating value from a 1x7 vector (element 1,1 in matrix divided by element 1,1 in vector, then element 1,2 in matrix divided by element 1,1 in vector etc.)
I.e. to simplify it would be like this:
a= [1, 2, 3
4, 5, 6]
b=[1, 2]
c=[1/1, 2/1, 3/1 = [1, 2, 3
4/2, 5/2, 6/2] 2, 2.5, 3]
I can't find the command to do this division (if it exists). Anyone that can help me?
BR,
Fredrik
There is no command in Prime to do what you want as there is no corresponding mathematical operation. So you would have to write your own small routine to do the job, which should not be difficult.
But there is a discrepancy between the explanation and the example in your text. Your explanation speaks of a 5x7 matrix and a 1x7 matrix but in the example you use a 2x3 and a 1x2 matrix? If I assume that element 1,2 means first row, second column, the explanation text of yours matches your example and I guess you meant a 1x5 matrix instead of the 1x7, right=
Have a look at the attached Mathcad 15 sheet. Unfortunately I do not have Prime at the moment.
I see you follow Fredrik's orgiginal text and instead of a 5x7 and 1x7 you use a 5x7 and 7x1 matrix. So Fredrik can chose whatever he needs or transpose his matrix B first.
BTW, you may shorten your routine for two lines by omitting z and replacing it with r.
Werner Exinger wrote:
I see you follow Fredrik's orgiginal text and instead of a 5x7 and 1x7 you use a 5x7 and 7x1 matrix. So Fredrik can chose whatever he needs or transpose his matrix B first.
Yes, but I have to admit that it looks a little dodgy.
BTW, you may shorten your routine for two lines by omitting z and replacing it with r.
Well spotted. My brain is struggling to engage after my holidays
I still do have Prime installed on a few machines, but I have MC15 open most of the time and I was too lazy to startup Prime as it takes way too long and is so slow and awkward to handle. So here are three solutions made in MC15 but which will work the same in Prime. Either you have MC15 and the converter installed anyway or you can retype it from the screenshots I provide.
The methods used are:
1) Vectorization. For this to work, matrix B has to be the same size as A, so B is transposed and augmented as many times as needed.
2) using range variables
3) the preferred method: using a custom made command "divide()"
Nicely done Werner
Or you could do it in a single statement:
If b were a row vector it would need to be transposed first.
Alan
Well done, but I have to say it looks like a 'dogs dinner'......
AlanStevens wrote:
Or you could do it in a single statement:
Frightening and impressive, indeed!
So I see that I wouldn't need vectorization at all in my first method.
Your method fails if the first row of matrix a contains at least one zero!
Here is an attempt for a repair using a boolean expression:
@Fredrik: In Prime you have a row selector which is missing in MC15. So you can replace (A[transpose][col 0] < infinity)[transpose] by (A[row 0]<infinity).
EDIT: Here is another one
and here thelast one 😉
I like the last one!
Alan
Good day, Could I take this conversation to the next step and request some additional help. I'm trying to reproduce some "Octave" (free MatLab) functionality within Prime. Octave allows division of mismatched matrices as simply as "Result = A\B". Of course Prime is not allowing this and I've attempted to cross my fingers and hope that the user defined function above would assist me but it's not evaluating the multi-dimensional matrices I have. Would anyone be up to challenge of evaluating the following and making suggestions as to what would need modified within the user defined function to get the two matrices to divide as desired (note the multi-dimensional format of A&B below!) :
Thanks in advance!
1) Its not clear to me what "division" result of those nested matrices you have in mind. Do you want the "divison" shown so far be applied one by one for all four pairs of 3x3 and 3x1 matrices?
2) Its better and attracts more attention if you open a new thread with our question. You may refer/link to this old thread and you should always also attach your worksheet if ever possible.
BTW, the divide function of mine you show will only work if the number of rows of the first matrix equals the number of columns of the second matrix and only the first row of the second matrix will be used. The original Poster (FredNils) never came back to this thread to make clear what exactly the demanded partial division should do. There was a discrepancy in his text right from the beginning .
So when you open a new thread you sure have to specify more clearly what exactly the function you demand should do and it would help if you attach examples (input matrices -> desired result).