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

Similar to vector matrix product, but different…

oguest
1-Visitor

Similar to vector matrix product, but different…

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

ACCEPTED SOLUTION

Accepted Solutions
RichardJ
19-Tanzanite
(To:oguest)

You can do it in a small program

View solution in original post

11 REPLIES 11
Fred_Kohlhepp
23-Emerald I
(To:oguest)

Not too hard

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

Fred_Kohlhepp
23-Emerald I
(To:oguest)

One line?  Sure! 

OK, one operation?

RichardJ
19-Tanzanite
(To:oguest)

You can do it in a small program

oguest
1-Visitor
(To:RichardJ)

Nice!
Thanks Richard, that is very concise 🙂
It ends up being one line when you put numbers in instead of letters 🙂
2015-09-02_16-30-44.jpg

StuartBruff
23-Emerald III
(To:oguest)

Oliver Guest wrote:

Nice!
Thanks Richard, that is very concise 🙂
It ends up being one line when you put numbers in instead of letters 🙂
2015-09-02_16-30-44.jpg

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

StuartBruff
23-Emerald III
(To:oguest)

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

Werner_E
25-Diamond I
(To:oguest)

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:

oguest
1-Visitor
(To:Werner_E)

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!

Announcements

Top Tags