how to construct a special matrix out of two lists
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have two lists as:
abs = a1, a2, a3, a4;
trs = t1, t2, t3, t4;
I like to build the following special matrix:
mat =
0, a2 t1, a3 t1, a4 t1,
a1 t2, 0, a3 t2, a4 t2,
a1 t3, a2 t3, 0, a4 t3,
a1 t4, a2 t4, a3 t3, 0
;
It is easy to create this matrix $mat$ by several matrix operations. However, I like to obtain $mat$ in a very compact Mathematica
code. In fact, a Mathematica
Function such as F[abs_,trs_]:=
is very much desirable as I will use it in many occasions.
list-manipulation matrix
add a comment |Â
up vote
1
down vote
favorite
I have two lists as:
abs = a1, a2, a3, a4;
trs = t1, t2, t3, t4;
I like to build the following special matrix:
mat =
0, a2 t1, a3 t1, a4 t1,
a1 t2, 0, a3 t2, a4 t2,
a1 t3, a2 t3, 0, a4 t3,
a1 t4, a2 t4, a3 t3, 0
;
It is easy to create this matrix $mat$ by several matrix operations. However, I like to obtain $mat$ in a very compact Mathematica
code. In fact, a Mathematica
Function such as F[abs_,trs_]:=
is very much desirable as I will use it in many occasions.
list-manipulation matrix
1
I assume thea3 t3
term should bea3 t4
â mikado
34 mins ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have two lists as:
abs = a1, a2, a3, a4;
trs = t1, t2, t3, t4;
I like to build the following special matrix:
mat =
0, a2 t1, a3 t1, a4 t1,
a1 t2, 0, a3 t2, a4 t2,
a1 t3, a2 t3, 0, a4 t3,
a1 t4, a2 t4, a3 t3, 0
;
It is easy to create this matrix $mat$ by several matrix operations. However, I like to obtain $mat$ in a very compact Mathematica
code. In fact, a Mathematica
Function such as F[abs_,trs_]:=
is very much desirable as I will use it in many occasions.
list-manipulation matrix
I have two lists as:
abs = a1, a2, a3, a4;
trs = t1, t2, t3, t4;
I like to build the following special matrix:
mat =
0, a2 t1, a3 t1, a4 t1,
a1 t2, 0, a3 t2, a4 t2,
a1 t3, a2 t3, 0, a4 t3,
a1 t4, a2 t4, a3 t3, 0
;
It is easy to create this matrix $mat$ by several matrix operations. However, I like to obtain $mat$ in a very compact Mathematica
code. In fact, a Mathematica
Function such as F[abs_,trs_]:=
is very much desirable as I will use it in many occasions.
list-manipulation matrix
list-manipulation matrix
asked 55 mins ago
Tebernus
407
407
1
I assume thea3 t3
term should bea3 t4
â mikado
34 mins ago
add a comment |Â
1
I assume thea3 t3
term should bea3 t4
â mikado
34 mins ago
1
1
I assume the
a3 t3
term should be a3 t4
â mikado
34 mins ago
I assume the
a3 t3
term should be a3 t4
â mikado
34 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
F[abs_, trs_] := ReplacePart[KroneckerProduct[trs, abs], k_, k_ -> 0]
F[a1, a2, a3, a4, t1, t2, t3, t4] // MatrixForm
$left(
beginarraycccc
0 & texta2 textt1 & texta3 textt1 & texta4 textt1 \
texta1 textt2 & 0 & texta3 textt2 & texta4 textt2 \
texta1 textt3 & texta2 textt3 & 0 & texta4 textt3 \
texta1 textt4 & texta2 textt4 & texta3 textt4 & 0
endarray
right)$
@GravityGuy: very nice construct...
â Tebernus
46 mins ago
3
Also:(# - DiagonalMatrix[Diagonal[#]]) & [KroneckerProduct[trs, abs]]
â J. M. is somewhat okay.â¦
45 mins ago
Yeah, the latter should be faster for large matrices...
â Henrik Schumacher
9 mins ago
add a comment |Â
up vote
1
down vote
Two other alternatives
Outer[Times, trs, abs] - DiagonalMatrix[abs*trs]
Transpose[trs].abs - DiagonalMatrix[abs*trs]
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
F[abs_, trs_] := ReplacePart[KroneckerProduct[trs, abs], k_, k_ -> 0]
F[a1, a2, a3, a4, t1, t2, t3, t4] // MatrixForm
$left(
beginarraycccc
0 & texta2 textt1 & texta3 textt1 & texta4 textt1 \
texta1 textt2 & 0 & texta3 textt2 & texta4 textt2 \
texta1 textt3 & texta2 textt3 & 0 & texta4 textt3 \
texta1 textt4 & texta2 textt4 & texta3 textt4 & 0
endarray
right)$
@GravityGuy: very nice construct...
â Tebernus
46 mins ago
3
Also:(# - DiagonalMatrix[Diagonal[#]]) & [KroneckerProduct[trs, abs]]
â J. M. is somewhat okay.â¦
45 mins ago
Yeah, the latter should be faster for large matrices...
â Henrik Schumacher
9 mins ago
add a comment |Â
up vote
3
down vote
F[abs_, trs_] := ReplacePart[KroneckerProduct[trs, abs], k_, k_ -> 0]
F[a1, a2, a3, a4, t1, t2, t3, t4] // MatrixForm
$left(
beginarraycccc
0 & texta2 textt1 & texta3 textt1 & texta4 textt1 \
texta1 textt2 & 0 & texta3 textt2 & texta4 textt2 \
texta1 textt3 & texta2 textt3 & 0 & texta4 textt3 \
texta1 textt4 & texta2 textt4 & texta3 textt4 & 0
endarray
right)$
@GravityGuy: very nice construct...
â Tebernus
46 mins ago
3
Also:(# - DiagonalMatrix[Diagonal[#]]) & [KroneckerProduct[trs, abs]]
â J. M. is somewhat okay.â¦
45 mins ago
Yeah, the latter should be faster for large matrices...
â Henrik Schumacher
9 mins ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
F[abs_, trs_] := ReplacePart[KroneckerProduct[trs, abs], k_, k_ -> 0]
F[a1, a2, a3, a4, t1, t2, t3, t4] // MatrixForm
$left(
beginarraycccc
0 & texta2 textt1 & texta3 textt1 & texta4 textt1 \
texta1 textt2 & 0 & texta3 textt2 & texta4 textt2 \
texta1 textt3 & texta2 textt3 & 0 & texta4 textt3 \
texta1 textt4 & texta2 textt4 & texta3 textt4 & 0
endarray
right)$
F[abs_, trs_] := ReplacePart[KroneckerProduct[trs, abs], k_, k_ -> 0]
F[a1, a2, a3, a4, t1, t2, t3, t4] // MatrixForm
$left(
beginarraycccc
0 & texta2 textt1 & texta3 textt1 & texta4 textt1 \
texta1 textt2 & 0 & texta3 textt2 & texta4 textt2 \
texta1 textt3 & texta2 textt3 & 0 & texta4 textt3 \
texta1 textt4 & texta2 textt4 & texta3 textt4 & 0
endarray
right)$
answered 48 mins ago
That Gravity Guy
1,269512
1,269512
@GravityGuy: very nice construct...
â Tebernus
46 mins ago
3
Also:(# - DiagonalMatrix[Diagonal[#]]) & [KroneckerProduct[trs, abs]]
â J. M. is somewhat okay.â¦
45 mins ago
Yeah, the latter should be faster for large matrices...
â Henrik Schumacher
9 mins ago
add a comment |Â
@GravityGuy: very nice construct...
â Tebernus
46 mins ago
3
Also:(# - DiagonalMatrix[Diagonal[#]]) & [KroneckerProduct[trs, abs]]
â J. M. is somewhat okay.â¦
45 mins ago
Yeah, the latter should be faster for large matrices...
â Henrik Schumacher
9 mins ago
@GravityGuy: very nice construct...
â Tebernus
46 mins ago
@GravityGuy: very nice construct...
â Tebernus
46 mins ago
3
3
Also:
(# - DiagonalMatrix[Diagonal[#]]) & [KroneckerProduct[trs, abs]]
â J. M. is somewhat okay.â¦
45 mins ago
Also:
(# - DiagonalMatrix[Diagonal[#]]) & [KroneckerProduct[trs, abs]]
â J. M. is somewhat okay.â¦
45 mins ago
Yeah, the latter should be faster for large matrices...
â Henrik Schumacher
9 mins ago
Yeah, the latter should be faster for large matrices...
â Henrik Schumacher
9 mins ago
add a comment |Â
up vote
1
down vote
Two other alternatives
Outer[Times, trs, abs] - DiagonalMatrix[abs*trs]
Transpose[trs].abs - DiagonalMatrix[abs*trs]
add a comment |Â
up vote
1
down vote
Two other alternatives
Outer[Times, trs, abs] - DiagonalMatrix[abs*trs]
Transpose[trs].abs - DiagonalMatrix[abs*trs]
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Two other alternatives
Outer[Times, trs, abs] - DiagonalMatrix[abs*trs]
Transpose[trs].abs - DiagonalMatrix[abs*trs]
Two other alternatives
Outer[Times, trs, abs] - DiagonalMatrix[abs*trs]
Transpose[trs].abs - DiagonalMatrix[abs*trs]
answered 31 mins ago
mikado
6,1071829
6,1071829
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182984%2fhow-to-construct-a-special-matrix-out-of-two-lists%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
I assume the
a3 t3
term should bea3 t4
â mikado
34 mins ago