Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
Hi, I don’t know what it is called, but I am looping for this functionality:
Give a vector with the same height as a matrix, find the matrix who’s row values are the matrix row values multiplied by the row value in the vector.
See attached image for a clearer explanation.
Is there an easy way to do this in MathCAD? I have found a work around, but it is not elegant.
Thanks
Oliver
Solved! Go to Solution.
Hi Fred,
Thanks for that. Very neat.
I was doing something similar in my work around, that involved using a loop. Its still a few lines though.
Is there no way to do this in one line?
Thanks
Oliver
OK, one operation?
You can do it in a small program
Nice!
Thanks Richard, that is very concise 🙂
It ends up being one line when you put numbers in instead of letters 🙂
Oliver Guest wrote:
Nice!
Thanks Richard, that is very concise 🙂
It ends up being one line when you put numbers in instead of letters 🙂
It's not normal practice to put the return the value in the for loop. Out of idle curiosity, I wondered whether there was a performance penalty for doing so and knocked together a quick worksheet to evaluate it. I also had a look at a couple of other methods and the timings surprised me: In the image below f1 is a functionalized version of your expression, f2 has the return value A in its standard place, f3 uses the Prime 3 row operator and performs scalar-array multiplication without explicit vectorization and f4 does it the hard way by replicating a column-wise to conform with b and then doing a vectorized multiplication of the two. Prime 3.1 results are in the top half of the image and Mathcad 15 M040 results in the bottom half (Note: Mathcad 15 doesn't have a row operator, so I did one of the standard tricks for accessing rows: transpose,use column operator, transpose back)
Stuart
Hi Stuart,
Very interesting results. Just so I'm sure that i follow correctly, could you post a screen shot of the functions you defined?
thanks
Oliver Guest wrote:
Hi Stuart,
Very interesting results. Just so I'm sure that i follow correctly, could you post a screen shot of the functions you defined?
Worse yet, I can link you to a thread containing the worksheets and images!
Prime 3.1 Column vs Row operator performance difference?
Stuart
Whats the reason you want it to be done in just one line/operation?
Because you need it multiple times in your sheet?
Then I would suggest you turn it into a user defined utility function:
Werner, that is fantastic!
Yes, I need to do it many many times in the same document.
This is a perfect solution and will make it so much simpler, thank you!