10 votes

Taxicab Geometry

Mathematica has a large set of graph functions. Here's a 10-by-10 graph of labeled nodes. We can use the graph to find every path that has a length of 9 between two nodes, and to display the paths. <...
creidhne's user avatar
  • 5,215
9 votes

Visualizing diagrams needed to compute $\operatorname{Tr}(A^3 (A^T)^3)$

Explanation why some graphs appear more than ones: It depends on the number of possible paths - some graphs have only one possibility, the graph below has four. Functions definitions: I borrowed <...
azerbajdzan's user avatar
  • 16.9k
8 votes

Why is Mathematica not simplifying eigenvalues?

The trick is to move the exp inside the sqrt and use the double angle trig rule. A = {{x*Exp[I*y], z}, {z, x*Exp[(-I)*y]}} {v1, v2} = Eigenvalues[A] ...
Nasser's user avatar
  • 144k
8 votes

Taxicab Geometry

Certainly a very wasteful method to generate all possible maths, but it's a start: ...
Henrik Schumacher's user avatar
8 votes

Taxicab Geometry

Let's start with an abstraction: routes = Permutations[{up, up, up, up, right, right, right, right, right}]; We now have 126 paths to get from {2,5} to {7,9} by ...
lericr's user avatar
  • 28.1k
7 votes

Element-wise vector-matrix exponentiation

Times @@@ Map[x^# &, A] {x1, x1 x2, x2}
eldo's user avatar
  • 70k
6 votes
Accepted

Fill a matrix with randomly placed elements that are a certain distance apart

If you really want to sample randomly (and uniformly), I believe you should first construct the set of all possible rows (or ensure the uniformness in some other way). Here is an approach using ...
Domen's user avatar
  • 24.9k
5 votes

Computing log-determinant?

The determinant of a matrix may be outside the usual 64-bit floating point range, even if the log determinant isn't. Hence using Log[Det[...]] to compute the log ...
Wicher's user avatar
  • 101
5 votes

Why is Mathematica not simplifying eigenvalues?

Eigenvalues[{{x*Exp[I*y], z}, {z, x*Exp[(-I)*y]}} // ComplexExpand]//FullSimplify ...
user64494's user avatar
  • 26.4k
5 votes

Element-wise vector-matrix exponentiation

Inner[ReverseApplied[Power], A, x, Times] (* {x1, x1 x2, x2} *)
user1066's user avatar
  • 18.2k
4 votes

Element-wise vector-matrix exponentiation

You can do it directly: Times @@ (x^Transpose@A) (* {x1, x1 x2, x2} *)
march's user avatar
  • 23.5k
4 votes

Visualizing diagrams needed to compute $\operatorname{Tr}(A^3 (A^T)^3)$

Here is a very very stupid, naive and brute-force approach. Unfortunately, I don't know how to control the position of graph edges, so the graphs are not as pretty as the ones you have. ...
Domen's user avatar
  • 24.9k
4 votes

Finite Differences:

...
Syed's user avatar
  • 54k
4 votes

Fill a matrix with randomly placed elements that are a certain distance apart

Using a RelationGraph projection: ...
vindobona's user avatar
  • 3,471
3 votes

Element-wise vector-matrix exponentiation

x = {x1, x2}; A = {{1, 0}, {1, 1}, {0, 1}}; Using Table: ...
E. Chan-López's user avatar
3 votes

Element-wise vector-matrix exponentiation

x = {x1, x2}; A = {{1, 0}, {1, 1}, {0, 1}} Pick[x, #, 1] & /@ A // Map[Apply[Times]] {x1, x1 x2, x2}
Syed's user avatar
  • 54k
3 votes

How to concatenate an array of matrices?

a = IdentityMatrix[2]; b = 2 * IdentityMatrix[2]; MapThread[Join, {a, b}] {{1, 0, 2, 0}, {0, 1, 0, 2}}
eldo's user avatar
  • 70k
3 votes

How do I flatten a matrix of lists while maintaining the structure of the list?

matrix = {{{a, b, c}, {e, f, g}}, {{h, i, j}, {k, l, m}}}; Using ArrayRules and GatherBy: <...
E. Chan-López's user avatar
3 votes

How do I flatten a matrix of lists while maintaining the structure of the list?

matrix = {{{a, b, c}, {e, f, g}}, {{h, i, j}, {k, l, m}}}; A variant of bmf's 2nd answer using MapApply (new in 13.1) ...
eldo's user avatar
  • 70k
3 votes

Finite Differences:

We can use Difference[#,n] to get n order difference. Flatten[#,{{2},{1}}] can be use to ...
cvgmt's user avatar
  • 72.9k
3 votes

Finite Differences:

The sole purpose of this post is to illustrate DifferenceDelta (and DiscretePlot): in-built function(s) for discrete calculus ...
ubpdqn's user avatar
  • 60.8k
2 votes

Using DeleteCases to delete vectors with particular index as 0

list = {{0, 1, 1, 0, 1}, {1, 0, 1, 1, 1}, {1, 1, 1, 1, 0}, {1, 0, 0, 1, 0}}; Pre-define pattern for better readability ...
eldo's user avatar
  • 70k
2 votes

Extract left-upper triangular data from a square matrix-form list

m = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}; Another way using Reap and ...
E. Chan-López's user avatar
2 votes

Split matrix by all-zero columns

mat = {{0, 0, 0, 0, 0, 1}, {1, 0, 0, 1, 0, 1}, {0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1}, {1, 1, 0, 1, 0, 0}, {0, 0, 0, 1, 0, 1}}; Using ...
eldo's user avatar
  • 70k
2 votes

Prepend 0 to sublists

list = {{7, 4, 9, 9, 7}, {4, 2, 5, 5, 2}, {6, 5, 9, 2, 4}, {1, 9, 4, 7, 2}}; Using the operator-form of Insert ...
eldo's user avatar
  • 70k
2 votes

Matrix crop (remove leading and trailing zeroes in matrix)

mat = ArrayPad[{{1, 2, 3}, {0, 0, 0}, {7, 8, 0}}, {{1, 2}, {2, 3}}]; Using SequenceSplit: ...
E. Chan-López's user avatar
2 votes

How to replace anti diagonal elements of a matrix

m = {{100, 9, 3, 8, 0}, {4, 200, 6, 4, 9}, {5, 2, 300, 7, 8}, {7, 9, 6, 400, 5}, {6, 1, 4, 2, 500}}; ...
eldo's user avatar
  • 70k
2 votes

How do I flatten a matrix of lists while maintaining the structure of the list?

Plus @@ ArrayFlatten[matrix, 1] (* {a + e + h + k, b + f + i + l, c + g + j + m} *)
user1066's user avatar
  • 18.2k
1 vote

Why is Mathematica not simplifying eigenvalues?

...
Bob Hanlon's user avatar
  • 158k
1 vote

Visualizing diagrams needed to compute $\operatorname{Tr}(A^3 (A^T)^3)$

This just an extended comment. When $d=3$ $A$ is a $n \times n$ array of independent unit Gaussian random variables, the trace of $A^d (A^T)^d$ is the sum of products of the form $$A_{i_1,j_1}A_{i_2,...
JimB's user avatar
  • 41.7k

Only top scored, non community-wiki answers of a minimum length are eligible