A question about product operation

Hello all!
I'm not sure if this was explained before, but I could not find any answer to this.
So, if i have x=[a b c] and y=[d e f] I'd like to know (if it's possible) how I could obtain:
.
z=
h i j
k l m
n o p
where:
h=a*d k=a*e n=a*f
i=b*d l=b*e o=b*f
j=c*d m=c*e p=c*f
Thanks!

 채택된 답변

Jan
Jan 2013년 9월 16일
편집: Jan 2013년 9월 16일

1 개 추천

x = [1, 2, 3]
y = [10, 20, 30]
z = x' * y
The matrix multiplication of a column vector with a row vector replies the dyadic product. x*y' would reply the dot-product.
Slower alternative:
z = bsxfun(@times, x', y)

댓글 수: 6

Dan P
Dan P 2013년 9월 16일
Thank you!
Simon
Simon 2013년 9월 16일
Beaten by 1 minute ... ;-)
Dan P
Dan P 2013년 9월 17일
Could you tell me how i could implement this in Simulink?
I put two constant blocks (one with x and one with y) and i put a product block. At the output of X, before connecting to the first input of the product i have to put a transpose block. I've tried "Transpose" and "Reshape" blocks but they didn't do the job. (the result it's not a 3x3 matrix) I also tried to use the blocks from the "User-defined functions" but I did not succeed.
Yes, if i make a .m file or simply type in command line z=x'*y it works (i have a 3x3 vector in workspace called z).
Any idea how this can be done in Simulink?
Jan
Jan 2013년 9월 17일
As described in the documentation, you can set the product block to "Matrix Mode". I've never worked with Simulink, but Google showed me this information after a few seconds of searching. Does it help already?
Sean de Wolski
Sean de Wolski 2013년 9월 17일
Of course you could also put this inside of a MATLAB function block.
Dan p wrote:
I also tried to use the blocks from the "User-defined functions" but I did not succeed.
Please show us, what you have tried and explain "did not succeed" with details.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Simon
Simon 2013년 9월 16일
편집: Simon 2013년 9월 16일

0 개 추천

Hi!
x = [1, 2, 3]; % row vector
y = [2; 3; 4]; % column vector
z = y * x;

카테고리

도움말 센터File Exchange에서 Modeling에 대해 자세히 알아보기

질문:

2013년 9월 16일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by