how to construct a special matrix out of two lists

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|improve this question

















  • 1




    I assume the a3 t3 term should be a3 t4
    – mikado
    34 mins ago














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.










share|improve this question

















  • 1




    I assume the a3 t3 term should be a3 t4
    – mikado
    34 mins ago












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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 55 mins ago









Tebernus

407




407







  • 1




    I assume the a3 t3 term should be a3 t4
    – mikado
    34 mins ago












  • 1




    I assume the a3 t3 term should be a3 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










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)$






share|improve this answer




















  • @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

















up vote
1
down vote













Two other alternatives



Outer[Times, trs, abs] - DiagonalMatrix[abs*trs]

Transpose[trs].abs - DiagonalMatrix[abs*trs]





share|improve this answer




















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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)$






    share|improve this answer




















    • @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














    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)$






    share|improve this answer




















    • @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












    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)$






    share|improve this answer












    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)$







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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
















    • @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










    up vote
    1
    down vote













    Two other alternatives



    Outer[Times, trs, abs] - DiagonalMatrix[abs*trs]

    Transpose[trs].abs - DiagonalMatrix[abs*trs]





    share|improve this answer
























      up vote
      1
      down vote













      Two other alternatives



      Outer[Times, trs, abs] - DiagonalMatrix[abs*trs]

      Transpose[trs].abs - DiagonalMatrix[abs*trs]





      share|improve this answer






















        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]





        share|improve this answer












        Two other alternatives



        Outer[Times, trs, abs] - DiagonalMatrix[abs*trs]

        Transpose[trs].abs - DiagonalMatrix[abs*trs]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 31 mins ago









        mikado

        6,1071829




        6,1071829



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke