Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Dear Mathcad community:
I'm continuing to develop some calculations in Mathcad Prime 9.0.0.0. On some occasions, I have encountered nested matrices that I have been able to "clean" without problems thanks to programs I found in the forum. However, the one shown in the attached file is different in a way I cannot understand, and it doesn't allow me to clean it. I would really appreciate it if someone could take a look at it and explain how I can solve this issue.
Thanks in advance!
Germán
Solved! Go to Solution.
The cleaning function won't help anyway because you calculated a nested vector with much more individuals values as you need.
Simplest solution IMHO is the usage of the row operator:
Each row of matrix p is multiplied with pi/4 and the square of the corresponding value in the vector D and then forms a new row in the resulting matrix.
Prime 9 sheet attached
Instead of converting, better preventing.
Like this?:
Then do:
and
Success!
Luc
You’re right, Luck, it’s better to prevent than to correct, although I admit that sometimes I have trouble working with vectors and matrices in Mathcad. Clearly, there’s some concept I haven’t fully grasped yet!
You understood perfectly what I was looking for; however, I tried to implement the solution you proposed and it returns the values correctly, but in a single vector, as I show in the image below. To be able to work with this vector, I would need to later separate the values by columns for each case study.
Nevertheless, one of the colleagues who responded afterward came up with a valid solution that solves this problem. Thank you very much for taking the time to respond and help me. Much appreciated.
Kind regards,
Germán
Forget what I said earlier, of course it works. I need to call the variable F without the subscripts afterward! My apologies!
One word of advice: Be VERY careful with evaluating a definition (is what you did by ending the assignment to F[a,c ...p[a,c with an =.).
Yes it works in many cases, but we've seen too many cases where it results in an error message, or the wrong impression of the answer (your case).
Success!
Luc
Hi,
Better to produce an unested matrix like this:-
Thank you very much, Terry. Your solution works, but I found it easier to implement Werner's solution in my calculations. However, I will keep your solution for other applications; it's always useful to keep different tools in mind to solve the same problem.
Thanks again for taking the time to answer my modest question!
Kind regards,
Germán
The cleaning function won't help anyway because you calculated a nested vector with much more individuals values as you need.
Simplest solution IMHO is the usage of the row operator:
Each row of matrix p is multiplied with pi/4 and the square of the corresponding value in the vector D and then forms a new row in the resulting matrix.
Prime 9 sheet attached
Just had a look why the cleanup functions of Valery and me did not work.
Valerys function was written specifically for the case that the inner matrices consist of one row only. Your inner matrices have 15 rows, so his function fails.
My function was a bit more generic, but it still fails in the special case that the input matrix would consist of just 1 row or just one column. Your nested matrix F is a vector with just one column ...
This could be fixed by adding two if-statements:
Now it works for your nested F as well, but because you created F to contain 15 matrices the size 15 x 4, you get a 225 x 4 result.
This "cleaned" matrix contains the 15 rows you are looking for, but also 210 rows you can't need. The matrix consists of every value (15) in the D matrix combined with every row (15) in the p matrix, so you got 225 rows.
What you need from this matrix are lines 1 and then every 16th line -> 17, 33, 39,...225.
You could extract those lines to get the desired matrix, but I strongly would advise that you use one of the methods shown before by Luc. Terry or me.
BTW, when you retyped my cleanUp function you made a mistake - the second loop with c should not be nested in the first one.
You're right, Werner. I was trying to obtain the values incorrectly, and you explained it perfectly. Using the row operator is the simplest solution, and it's what I implemented in my calculations because I don't have to create new variables. However, either of the other two options offered by Luc or Terry is perfectly valid, and I'll save them for other applications that I might need.
I had used Valery's function several times before in my calculations, but it's true that the inner matrices were rows that I had previously built with the 'augment' function to combine several vectors into a single matrix. Nevertheless, I'll also keep the new 'cleanup' function for any future applications.
Thank you very much for your time in responding and for your valuable explanations; they help me a lot!
Kind regards,
Germán