Skipping indices in a product The Next CEO of Stack OverflowTensorContract of inverse matrixWhat's the best way to generate all the upper triangular matrix whose singular values are given?What is the fastest way to obtain the eigenvalues of a Wishart matrix?Evaluating the product of a matrix sequenceNearest Kronecker ProductMapping over two indices with a conditionBilinear Dot FunctionWhy does Eigenvalues work for a matrix $M$ but not $M$?Numerically computing the eigenvalues of an infinite-dimensional tridiagonal matrixInverting a matrix when its elements are given by difficult expressions?

Does higher Oxidation/ reduction potential translate to higher energy storage in battery?

Aggressive Under-Indexing and no data for missing index

TikZ: How to fill area with a special pattern?

Are the names of these months realistic?

Is there such a thing as a proper verb, like a proper noun?

Is it OK to decorate a log book cover?

Calculate the Mean mean of two numbers

Is it correct to say moon starry nights?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

Vector calculus integration identity problem

Help/tips for a first time writer?

What would be the main consequences for a country leaving the WTO?

How to use ReplaceAll on an expression that contains a rule

Could a dragon use its wings to swim?

Is dried pee considered dirt?

Defamation due to breach of confidentiality

Which Pokemon have a special animation when running with them out of their pokeball?

What difference does it make using sed with/without whitespaces?

Is there a reasonable and studied concept of reduction between regular languages?

How do you define an element with an ID attribute using LWC?

Won the lottery - how do I keep the money?

What day is it again?

Computationally populating tables with probability data



Skipping indices in a product



The Next CEO of Stack OverflowTensorContract of inverse matrixWhat's the best way to generate all the upper triangular matrix whose singular values are given?What is the fastest way to obtain the eigenvalues of a Wishart matrix?Evaluating the product of a matrix sequenceNearest Kronecker ProductMapping over two indices with a conditionBilinear Dot FunctionWhy does Eigenvalues work for a matrix $M$ but not $M$?Numerically computing the eigenvalues of an infinite-dimensional tridiagonal matrixInverting a matrix when its elements are given by difficult expressions?










2












$begingroup$


I have a matrix $A$ for which I want to compute the quantity $Tlambda_j = Pi_lambda_ine lambda_j fracA - lambda_i Ilambda_j-lambda_i$, where $lambda_i$ ($lambda_j$) denote the eigenvalues of $A$. How can this be implemented in Mathematica? Just gave a try here:



A = 1, 0, 0, 1,0, 1, 2, 0,1, 1, 0, 2,0, 0, 0, 1;
Eigenvalues[A]



2, -1, 1, 1




Tj = Product[(A - Eigenvalues[A][[i]] IdentityMatrix[4])/(
Eigenvalues[A][[j]] - Eigenvalues[A][[i]]), i, 1, 4]









share|improve this question











$endgroup$











  • $begingroup$
    in which part exactly you want to exclude it in Tj !??
    $endgroup$
    – Alrubaie
    2 days ago










  • $begingroup$
    do you want it to be skipped put not Zero right !?
    $endgroup$
    – Alrubaie
    2 days ago










  • $begingroup$
    @Alrubaie, there was a typo in my post. Just edited it. I want the denominator to be non-zero and hence avoid the case for which $i=j$.
    $endgroup$
    – Tobias Fritzn
    2 days ago










  • $begingroup$
    @Alrubaie, my $i$ and $j$ are not the indices in my question. They are the eigenvalues. I should have used something like $lambda_i$ and $lambda_j$.
    $endgroup$
    – Tobias Fritzn
    2 days ago






  • 2




    $begingroup$
    That product is presumably a matrix multiplication?
    $endgroup$
    – J. M. is slightly pensive
    2 days ago















2












$begingroup$


I have a matrix $A$ for which I want to compute the quantity $Tlambda_j = Pi_lambda_ine lambda_j fracA - lambda_i Ilambda_j-lambda_i$, where $lambda_i$ ($lambda_j$) denote the eigenvalues of $A$. How can this be implemented in Mathematica? Just gave a try here:



A = 1, 0, 0, 1,0, 1, 2, 0,1, 1, 0, 2,0, 0, 0, 1;
Eigenvalues[A]



2, -1, 1, 1




Tj = Product[(A - Eigenvalues[A][[i]] IdentityMatrix[4])/(
Eigenvalues[A][[j]] - Eigenvalues[A][[i]]), i, 1, 4]









share|improve this question











$endgroup$











  • $begingroup$
    in which part exactly you want to exclude it in Tj !??
    $endgroup$
    – Alrubaie
    2 days ago










  • $begingroup$
    do you want it to be skipped put not Zero right !?
    $endgroup$
    – Alrubaie
    2 days ago










  • $begingroup$
    @Alrubaie, there was a typo in my post. Just edited it. I want the denominator to be non-zero and hence avoid the case for which $i=j$.
    $endgroup$
    – Tobias Fritzn
    2 days ago










  • $begingroup$
    @Alrubaie, my $i$ and $j$ are not the indices in my question. They are the eigenvalues. I should have used something like $lambda_i$ and $lambda_j$.
    $endgroup$
    – Tobias Fritzn
    2 days ago






  • 2




    $begingroup$
    That product is presumably a matrix multiplication?
    $endgroup$
    – J. M. is slightly pensive
    2 days ago













2












2








2





$begingroup$


I have a matrix $A$ for which I want to compute the quantity $Tlambda_j = Pi_lambda_ine lambda_j fracA - lambda_i Ilambda_j-lambda_i$, where $lambda_i$ ($lambda_j$) denote the eigenvalues of $A$. How can this be implemented in Mathematica? Just gave a try here:



A = 1, 0, 0, 1,0, 1, 2, 0,1, 1, 0, 2,0, 0, 0, 1;
Eigenvalues[A]



2, -1, 1, 1




Tj = Product[(A - Eigenvalues[A][[i]] IdentityMatrix[4])/(
Eigenvalues[A][[j]] - Eigenvalues[A][[i]]), i, 1, 4]









share|improve this question











$endgroup$




I have a matrix $A$ for which I want to compute the quantity $Tlambda_j = Pi_lambda_ine lambda_j fracA - lambda_i Ilambda_j-lambda_i$, where $lambda_i$ ($lambda_j$) denote the eigenvalues of $A$. How can this be implemented in Mathematica? Just gave a try here:



A = 1, 0, 0, 1,0, 1, 2, 0,1, 1, 0, 2,0, 0, 0, 1;
Eigenvalues[A]



2, -1, 1, 1




Tj = Product[(A - Eigenvalues[A][[i]] IdentityMatrix[4])/(
Eigenvalues[A][[j]] - Eigenvalues[A][[i]]), i, 1, 4]






matrix linear-algebra operators






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Michael E2

150k12203482




150k12203482










asked 2 days ago









Tobias FritznTobias Fritzn

1795




1795











  • $begingroup$
    in which part exactly you want to exclude it in Tj !??
    $endgroup$
    – Alrubaie
    2 days ago










  • $begingroup$
    do you want it to be skipped put not Zero right !?
    $endgroup$
    – Alrubaie
    2 days ago










  • $begingroup$
    @Alrubaie, there was a typo in my post. Just edited it. I want the denominator to be non-zero and hence avoid the case for which $i=j$.
    $endgroup$
    – Tobias Fritzn
    2 days ago










  • $begingroup$
    @Alrubaie, my $i$ and $j$ are not the indices in my question. They are the eigenvalues. I should have used something like $lambda_i$ and $lambda_j$.
    $endgroup$
    – Tobias Fritzn
    2 days ago






  • 2




    $begingroup$
    That product is presumably a matrix multiplication?
    $endgroup$
    – J. M. is slightly pensive
    2 days ago
















  • $begingroup$
    in which part exactly you want to exclude it in Tj !??
    $endgroup$
    – Alrubaie
    2 days ago










  • $begingroup$
    do you want it to be skipped put not Zero right !?
    $endgroup$
    – Alrubaie
    2 days ago










  • $begingroup$
    @Alrubaie, there was a typo in my post. Just edited it. I want the denominator to be non-zero and hence avoid the case for which $i=j$.
    $endgroup$
    – Tobias Fritzn
    2 days ago










  • $begingroup$
    @Alrubaie, my $i$ and $j$ are not the indices in my question. They are the eigenvalues. I should have used something like $lambda_i$ and $lambda_j$.
    $endgroup$
    – Tobias Fritzn
    2 days ago






  • 2




    $begingroup$
    That product is presumably a matrix multiplication?
    $endgroup$
    – J. M. is slightly pensive
    2 days ago















$begingroup$
in which part exactly you want to exclude it in Tj !??
$endgroup$
– Alrubaie
2 days ago




$begingroup$
in which part exactly you want to exclude it in Tj !??
$endgroup$
– Alrubaie
2 days ago












$begingroup$
do you want it to be skipped put not Zero right !?
$endgroup$
– Alrubaie
2 days ago




$begingroup$
do you want it to be skipped put not Zero right !?
$endgroup$
– Alrubaie
2 days ago












$begingroup$
@Alrubaie, there was a typo in my post. Just edited it. I want the denominator to be non-zero and hence avoid the case for which $i=j$.
$endgroup$
– Tobias Fritzn
2 days ago




$begingroup$
@Alrubaie, there was a typo in my post. Just edited it. I want the denominator to be non-zero and hence avoid the case for which $i=j$.
$endgroup$
– Tobias Fritzn
2 days ago












$begingroup$
@Alrubaie, my $i$ and $j$ are not the indices in my question. They are the eigenvalues. I should have used something like $lambda_i$ and $lambda_j$.
$endgroup$
– Tobias Fritzn
2 days ago




$begingroup$
@Alrubaie, my $i$ and $j$ are not the indices in my question. They are the eigenvalues. I should have used something like $lambda_i$ and $lambda_j$.
$endgroup$
– Tobias Fritzn
2 days ago




2




2




$begingroup$
That product is presumably a matrix multiplication?
$endgroup$
– J. M. is slightly pensive
2 days ago




$begingroup$
That product is presumably a matrix multiplication?
$endgroup$
– J. M. is slightly pensive
2 days ago










4 Answers
4






active

oldest

votes


















4












$begingroup$

Here is my pedestrian implementation of your formula:



a = 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 0, 0, 0, 1;

ClearAll[t]
t[amat_, j_] := Module[
evals, usable,
evals = Eigenvalues[amat];
usable = DeleteDuplicates@Cases[evals, Except@evals[[j]] ];
Dot @@
Table[
(amat - i IdentityMatrix[Length[amat]])/(evals[[j]] - i),
i, usable
]
]

t[a, 4]


Mathematica graphics



You do not provide an example of desired output, so I will let you check whether this is what you expect.






share|improve this answer









$endgroup$












  • $begingroup$
    Thanks, @MarcoB. It leads precisely to the expected result. However, it looks too complicated. Nevertheless, it is fine as it works.
    $endgroup$
    – Tobias Fritzn
    2 days ago



















3












$begingroup$

Something like this?



Clear[A, evals, T]
A = 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 0, 0, 0, 1;
T[A_?MatrixQ, j_Integer] := With[
evals = Eigenvalues[A], id = IdentityMatrix@Length@A,
Dot @@ Table[
If[evals[[j]] - evals[[i]] == 0, id, (A - evals[[i]] id)/(evals[[j]] - evals[[i]])],
i, Length@A
]
]

MatrixForm /@ Array[T[A, #] &, 4]


enter image description here






share|improve this answer









$endgroup$




















    2












    $begingroup$

    This



    A = 1, 0, 0, 1,0, 1, 2, 0,1, 1, 0, 2,0, 0, 0, 1;
    e=Eigenvalues[A];
    Map[(A-e[[#[[1]]]]*IdentityMatrix[4])/(e[[#[[2]]]]-e[[#[[1]]]])&,
    DeleteCases[Tuples[Range[4],2],i_,i_]]


    generates your twelve matricies with i not equal to j.



    Put Dot@@ in front of that Map to form the dot product of the 12 matricies.



    That works by forming every possible distinct i,j pair and then using those in the Map



    If it might be easier to read you can also write it this way



    Map[(ei=e[[#[[1]]]];ej=e[[#[[2]]]];
    (A-ei*IdentityMatrix[4])/(ej-ei))&,
    DeleteCases[Tuples[Range[4],2],i_,i_]]





    share|improve this answer











    $endgroup$












    • $begingroup$
      Should e[[#[[2]]]]-e[[[[1]]]] be e[[#[[2]]]]-e[[#[[1]]]]?
      $endgroup$
      – That Gravity Guy
      2 days ago










    • $begingroup$
      @ThatGravityGuy Yes! Good catch. Thank you! Corrected.
      $endgroup$
      – Bill
      2 days ago


















    0












    $begingroup$

    Another way:



    ClearAll[t];
    t[j_Integer, A_?SquareMatrixQ] := t[j, A, Eigenvalues@A]; (* add the eigenvalues *)
    t[j_Integer, A_?SquareMatrixQ, evs_?VectorQ] /; Length@A == Length@evs := (* arg checks *)=
    Fold[
    #1.(A - #2 IdentityMatrix[Length@A])/(evs[[j]] - #2) &,
    IdentityMatrix[Length@A],
    Pick[evs, Unitize[evs - evs[[j]]], 1] (* Pick nonzero differences *)
    ];


    Performance tuning: One can use DeleteCases[evs, e_ /; e == evs[[j]]] to pick the eigenvalues that give a nonzero difference. It makes no consistent difference to the timing on a 101 x 101 machine real matrix. One can save a little time by computing the identity matrix once and using With[] to inject it in the two places it occurs. One can also save time using dot = (dot = Dot; #2) & instead of Dot to skip the multiplication by the identity matrix (the first step of Fold[]). The differences evs - evs[[j]] appear twice, so they can be replaced by a single computation like the identity matrix. It can make up to a 10% improvement.






    share|improve this answer









    $endgroup$













      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      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%2f194194%2fskipping-indices-in-a-product%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4












      $begingroup$

      Here is my pedestrian implementation of your formula:



      a = 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 0, 0, 0, 1;

      ClearAll[t]
      t[amat_, j_] := Module[
      evals, usable,
      evals = Eigenvalues[amat];
      usable = DeleteDuplicates@Cases[evals, Except@evals[[j]] ];
      Dot @@
      Table[
      (amat - i IdentityMatrix[Length[amat]])/(evals[[j]] - i),
      i, usable
      ]
      ]

      t[a, 4]


      Mathematica graphics



      You do not provide an example of desired output, so I will let you check whether this is what you expect.






      share|improve this answer









      $endgroup$












      • $begingroup$
        Thanks, @MarcoB. It leads precisely to the expected result. However, it looks too complicated. Nevertheless, it is fine as it works.
        $endgroup$
        – Tobias Fritzn
        2 days ago
















      4












      $begingroup$

      Here is my pedestrian implementation of your formula:



      a = 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 0, 0, 0, 1;

      ClearAll[t]
      t[amat_, j_] := Module[
      evals, usable,
      evals = Eigenvalues[amat];
      usable = DeleteDuplicates@Cases[evals, Except@evals[[j]] ];
      Dot @@
      Table[
      (amat - i IdentityMatrix[Length[amat]])/(evals[[j]] - i),
      i, usable
      ]
      ]

      t[a, 4]


      Mathematica graphics



      You do not provide an example of desired output, so I will let you check whether this is what you expect.






      share|improve this answer









      $endgroup$












      • $begingroup$
        Thanks, @MarcoB. It leads precisely to the expected result. However, it looks too complicated. Nevertheless, it is fine as it works.
        $endgroup$
        – Tobias Fritzn
        2 days ago














      4












      4








      4





      $begingroup$

      Here is my pedestrian implementation of your formula:



      a = 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 0, 0, 0, 1;

      ClearAll[t]
      t[amat_, j_] := Module[
      evals, usable,
      evals = Eigenvalues[amat];
      usable = DeleteDuplicates@Cases[evals, Except@evals[[j]] ];
      Dot @@
      Table[
      (amat - i IdentityMatrix[Length[amat]])/(evals[[j]] - i),
      i, usable
      ]
      ]

      t[a, 4]


      Mathematica graphics



      You do not provide an example of desired output, so I will let you check whether this is what you expect.






      share|improve this answer









      $endgroup$



      Here is my pedestrian implementation of your formula:



      a = 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 0, 0, 0, 1;

      ClearAll[t]
      t[amat_, j_] := Module[
      evals, usable,
      evals = Eigenvalues[amat];
      usable = DeleteDuplicates@Cases[evals, Except@evals[[j]] ];
      Dot @@
      Table[
      (amat - i IdentityMatrix[Length[amat]])/(evals[[j]] - i),
      i, usable
      ]
      ]

      t[a, 4]


      Mathematica graphics



      You do not provide an example of desired output, so I will let you check whether this is what you expect.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered 2 days ago









      MarcoBMarcoB

      38.2k556114




      38.2k556114











      • $begingroup$
        Thanks, @MarcoB. It leads precisely to the expected result. However, it looks too complicated. Nevertheless, it is fine as it works.
        $endgroup$
        – Tobias Fritzn
        2 days ago

















      • $begingroup$
        Thanks, @MarcoB. It leads precisely to the expected result. However, it looks too complicated. Nevertheless, it is fine as it works.
        $endgroup$
        – Tobias Fritzn
        2 days ago
















      $begingroup$
      Thanks, @MarcoB. It leads precisely to the expected result. However, it looks too complicated. Nevertheless, it is fine as it works.
      $endgroup$
      – Tobias Fritzn
      2 days ago





      $begingroup$
      Thanks, @MarcoB. It leads precisely to the expected result. However, it looks too complicated. Nevertheless, it is fine as it works.
      $endgroup$
      – Tobias Fritzn
      2 days ago












      3












      $begingroup$

      Something like this?



      Clear[A, evals, T]
      A = 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 0, 0, 0, 1;
      T[A_?MatrixQ, j_Integer] := With[
      evals = Eigenvalues[A], id = IdentityMatrix@Length@A,
      Dot @@ Table[
      If[evals[[j]] - evals[[i]] == 0, id, (A - evals[[i]] id)/(evals[[j]] - evals[[i]])],
      i, Length@A
      ]
      ]

      MatrixForm /@ Array[T[A, #] &, 4]


      enter image description here






      share|improve this answer









      $endgroup$

















        3












        $begingroup$

        Something like this?



        Clear[A, evals, T]
        A = 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 0, 0, 0, 1;
        T[A_?MatrixQ, j_Integer] := With[
        evals = Eigenvalues[A], id = IdentityMatrix@Length@A,
        Dot @@ Table[
        If[evals[[j]] - evals[[i]] == 0, id, (A - evals[[i]] id)/(evals[[j]] - evals[[i]])],
        i, Length@A
        ]
        ]

        MatrixForm /@ Array[T[A, #] &, 4]


        enter image description here






        share|improve this answer









        $endgroup$















          3












          3








          3





          $begingroup$

          Something like this?



          Clear[A, evals, T]
          A = 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 0, 0, 0, 1;
          T[A_?MatrixQ, j_Integer] := With[
          evals = Eigenvalues[A], id = IdentityMatrix@Length@A,
          Dot @@ Table[
          If[evals[[j]] - evals[[i]] == 0, id, (A - evals[[i]] id)/(evals[[j]] - evals[[i]])],
          i, Length@A
          ]
          ]

          MatrixForm /@ Array[T[A, #] &, 4]


          enter image description here






          share|improve this answer









          $endgroup$



          Something like this?



          Clear[A, evals, T]
          A = 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 0, 0, 0, 1;
          T[A_?MatrixQ, j_Integer] := With[
          evals = Eigenvalues[A], id = IdentityMatrix@Length@A,
          Dot @@ Table[
          If[evals[[j]] - evals[[i]] == 0, id, (A - evals[[i]] id)/(evals[[j]] - evals[[i]])],
          i, Length@A
          ]
          ]

          MatrixForm /@ Array[T[A, #] &, 4]


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          That Gravity GuyThat Gravity Guy

          2,1411615




          2,1411615





















              2












              $begingroup$

              This



              A = 1, 0, 0, 1,0, 1, 2, 0,1, 1, 0, 2,0, 0, 0, 1;
              e=Eigenvalues[A];
              Map[(A-e[[#[[1]]]]*IdentityMatrix[4])/(e[[#[[2]]]]-e[[#[[1]]]])&,
              DeleteCases[Tuples[Range[4],2],i_,i_]]


              generates your twelve matricies with i not equal to j.



              Put Dot@@ in front of that Map to form the dot product of the 12 matricies.



              That works by forming every possible distinct i,j pair and then using those in the Map



              If it might be easier to read you can also write it this way



              Map[(ei=e[[#[[1]]]];ej=e[[#[[2]]]];
              (A-ei*IdentityMatrix[4])/(ej-ei))&,
              DeleteCases[Tuples[Range[4],2],i_,i_]]





              share|improve this answer











              $endgroup$












              • $begingroup$
                Should e[[#[[2]]]]-e[[[[1]]]] be e[[#[[2]]]]-e[[#[[1]]]]?
                $endgroup$
                – That Gravity Guy
                2 days ago










              • $begingroup$
                @ThatGravityGuy Yes! Good catch. Thank you! Corrected.
                $endgroup$
                – Bill
                2 days ago















              2












              $begingroup$

              This



              A = 1, 0, 0, 1,0, 1, 2, 0,1, 1, 0, 2,0, 0, 0, 1;
              e=Eigenvalues[A];
              Map[(A-e[[#[[1]]]]*IdentityMatrix[4])/(e[[#[[2]]]]-e[[#[[1]]]])&,
              DeleteCases[Tuples[Range[4],2],i_,i_]]


              generates your twelve matricies with i not equal to j.



              Put Dot@@ in front of that Map to form the dot product of the 12 matricies.



              That works by forming every possible distinct i,j pair and then using those in the Map



              If it might be easier to read you can also write it this way



              Map[(ei=e[[#[[1]]]];ej=e[[#[[2]]]];
              (A-ei*IdentityMatrix[4])/(ej-ei))&,
              DeleteCases[Tuples[Range[4],2],i_,i_]]





              share|improve this answer











              $endgroup$












              • $begingroup$
                Should e[[#[[2]]]]-e[[[[1]]]] be e[[#[[2]]]]-e[[#[[1]]]]?
                $endgroup$
                – That Gravity Guy
                2 days ago










              • $begingroup$
                @ThatGravityGuy Yes! Good catch. Thank you! Corrected.
                $endgroup$
                – Bill
                2 days ago













              2












              2








              2





              $begingroup$

              This



              A = 1, 0, 0, 1,0, 1, 2, 0,1, 1, 0, 2,0, 0, 0, 1;
              e=Eigenvalues[A];
              Map[(A-e[[#[[1]]]]*IdentityMatrix[4])/(e[[#[[2]]]]-e[[#[[1]]]])&,
              DeleteCases[Tuples[Range[4],2],i_,i_]]


              generates your twelve matricies with i not equal to j.



              Put Dot@@ in front of that Map to form the dot product of the 12 matricies.



              That works by forming every possible distinct i,j pair and then using those in the Map



              If it might be easier to read you can also write it this way



              Map[(ei=e[[#[[1]]]];ej=e[[#[[2]]]];
              (A-ei*IdentityMatrix[4])/(ej-ei))&,
              DeleteCases[Tuples[Range[4],2],i_,i_]]





              share|improve this answer











              $endgroup$



              This



              A = 1, 0, 0, 1,0, 1, 2, 0,1, 1, 0, 2,0, 0, 0, 1;
              e=Eigenvalues[A];
              Map[(A-e[[#[[1]]]]*IdentityMatrix[4])/(e[[#[[2]]]]-e[[#[[1]]]])&,
              DeleteCases[Tuples[Range[4],2],i_,i_]]


              generates your twelve matricies with i not equal to j.



              Put Dot@@ in front of that Map to form the dot product of the 12 matricies.



              That works by forming every possible distinct i,j pair and then using those in the Map



              If it might be easier to read you can also write it this way



              Map[(ei=e[[#[[1]]]];ej=e[[#[[2]]]];
              (A-ei*IdentityMatrix[4])/(ej-ei))&,
              DeleteCases[Tuples[Range[4],2],i_,i_]]






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 2 days ago

























              answered 2 days ago









              BillBill

              5,89569




              5,89569











              • $begingroup$
                Should e[[#[[2]]]]-e[[[[1]]]] be e[[#[[2]]]]-e[[#[[1]]]]?
                $endgroup$
                – That Gravity Guy
                2 days ago










              • $begingroup$
                @ThatGravityGuy Yes! Good catch. Thank you! Corrected.
                $endgroup$
                – Bill
                2 days ago
















              • $begingroup$
                Should e[[#[[2]]]]-e[[[[1]]]] be e[[#[[2]]]]-e[[#[[1]]]]?
                $endgroup$
                – That Gravity Guy
                2 days ago










              • $begingroup$
                @ThatGravityGuy Yes! Good catch. Thank you! Corrected.
                $endgroup$
                – Bill
                2 days ago















              $begingroup$
              Should e[[#[[2]]]]-e[[[[1]]]] be e[[#[[2]]]]-e[[#[[1]]]]?
              $endgroup$
              – That Gravity Guy
              2 days ago




              $begingroup$
              Should e[[#[[2]]]]-e[[[[1]]]] be e[[#[[2]]]]-e[[#[[1]]]]?
              $endgroup$
              – That Gravity Guy
              2 days ago












              $begingroup$
              @ThatGravityGuy Yes! Good catch. Thank you! Corrected.
              $endgroup$
              – Bill
              2 days ago




              $begingroup$
              @ThatGravityGuy Yes! Good catch. Thank you! Corrected.
              $endgroup$
              – Bill
              2 days ago











              0












              $begingroup$

              Another way:



              ClearAll[t];
              t[j_Integer, A_?SquareMatrixQ] := t[j, A, Eigenvalues@A]; (* add the eigenvalues *)
              t[j_Integer, A_?SquareMatrixQ, evs_?VectorQ] /; Length@A == Length@evs := (* arg checks *)=
              Fold[
              #1.(A - #2 IdentityMatrix[Length@A])/(evs[[j]] - #2) &,
              IdentityMatrix[Length@A],
              Pick[evs, Unitize[evs - evs[[j]]], 1] (* Pick nonzero differences *)
              ];


              Performance tuning: One can use DeleteCases[evs, e_ /; e == evs[[j]]] to pick the eigenvalues that give a nonzero difference. It makes no consistent difference to the timing on a 101 x 101 machine real matrix. One can save a little time by computing the identity matrix once and using With[] to inject it in the two places it occurs. One can also save time using dot = (dot = Dot; #2) & instead of Dot to skip the multiplication by the identity matrix (the first step of Fold[]). The differences evs - evs[[j]] appear twice, so they can be replaced by a single computation like the identity matrix. It can make up to a 10% improvement.






              share|improve this answer









              $endgroup$

















                0












                $begingroup$

                Another way:



                ClearAll[t];
                t[j_Integer, A_?SquareMatrixQ] := t[j, A, Eigenvalues@A]; (* add the eigenvalues *)
                t[j_Integer, A_?SquareMatrixQ, evs_?VectorQ] /; Length@A == Length@evs := (* arg checks *)=
                Fold[
                #1.(A - #2 IdentityMatrix[Length@A])/(evs[[j]] - #2) &,
                IdentityMatrix[Length@A],
                Pick[evs, Unitize[evs - evs[[j]]], 1] (* Pick nonzero differences *)
                ];


                Performance tuning: One can use DeleteCases[evs, e_ /; e == evs[[j]]] to pick the eigenvalues that give a nonzero difference. It makes no consistent difference to the timing on a 101 x 101 machine real matrix. One can save a little time by computing the identity matrix once and using With[] to inject it in the two places it occurs. One can also save time using dot = (dot = Dot; #2) & instead of Dot to skip the multiplication by the identity matrix (the first step of Fold[]). The differences evs - evs[[j]] appear twice, so they can be replaced by a single computation like the identity matrix. It can make up to a 10% improvement.






                share|improve this answer









                $endgroup$















                  0












                  0








                  0





                  $begingroup$

                  Another way:



                  ClearAll[t];
                  t[j_Integer, A_?SquareMatrixQ] := t[j, A, Eigenvalues@A]; (* add the eigenvalues *)
                  t[j_Integer, A_?SquareMatrixQ, evs_?VectorQ] /; Length@A == Length@evs := (* arg checks *)=
                  Fold[
                  #1.(A - #2 IdentityMatrix[Length@A])/(evs[[j]] - #2) &,
                  IdentityMatrix[Length@A],
                  Pick[evs, Unitize[evs - evs[[j]]], 1] (* Pick nonzero differences *)
                  ];


                  Performance tuning: One can use DeleteCases[evs, e_ /; e == evs[[j]]] to pick the eigenvalues that give a nonzero difference. It makes no consistent difference to the timing on a 101 x 101 machine real matrix. One can save a little time by computing the identity matrix once and using With[] to inject it in the two places it occurs. One can also save time using dot = (dot = Dot; #2) & instead of Dot to skip the multiplication by the identity matrix (the first step of Fold[]). The differences evs - evs[[j]] appear twice, so they can be replaced by a single computation like the identity matrix. It can make up to a 10% improvement.






                  share|improve this answer









                  $endgroup$



                  Another way:



                  ClearAll[t];
                  t[j_Integer, A_?SquareMatrixQ] := t[j, A, Eigenvalues@A]; (* add the eigenvalues *)
                  t[j_Integer, A_?SquareMatrixQ, evs_?VectorQ] /; Length@A == Length@evs := (* arg checks *)=
                  Fold[
                  #1.(A - #2 IdentityMatrix[Length@A])/(evs[[j]] - #2) &,
                  IdentityMatrix[Length@A],
                  Pick[evs, Unitize[evs - evs[[j]]], 1] (* Pick nonzero differences *)
                  ];


                  Performance tuning: One can use DeleteCases[evs, e_ /; e == evs[[j]]] to pick the eigenvalues that give a nonzero difference. It makes no consistent difference to the timing on a 101 x 101 machine real matrix. One can save a little time by computing the identity matrix once and using With[] to inject it in the two places it occurs. One can also save time using dot = (dot = Dot; #2) & instead of Dot to skip the multiplication by the identity matrix (the first step of Fold[]). The differences evs - evs[[j]] appear twice, so they can be replaced by a single computation like the identity matrix. It can make up to a 10% improvement.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  Michael E2Michael E2

                  150k12203482




                  150k12203482



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Mathematica Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f194194%2fskipping-indices-in-a-product%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                      Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                      Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.