Tag Info

Hot answers tagged

9

Since Mathematica offers powerful symbolic capabilities I find that more effective solution to the problem uses exact numbers instead of machine precission ones and consequently exploits appropriate symbolic functions. The given matrix m: m = {{0.04 - 0.4 b, 0, 0.04 - 0.4 b}, {0, -0.08 - 1.2 b, -0.06 - 0.9 b}, {1.04 - 0.4 b, 2.08 - 0.8 b, 0}}; ...


8

The key to speedup here is generating the set of random number in one go instead of calling RandomVariate repeatedly. Generally, instead of Table[RandomVariate[...], {size}] use RandomVariate[..., size] It can also generate a multidimensional array of random values in one go. I rewrote your code to do this: out = AbsoluteTiming[Table[ ...


6

Transpose[{t, #}] & /@ Z {{{{129600, 30240}, 1}, {{30240, 10080}, 3}, {{10080, 1440}, 3}, {{1440, 0}, 7}}, {{{129600, 30240}, 8}, {{30240, 10080}, 6}, {{10080, 1440}, 6}, {{1440, 0}, 3}}, {{{129600, 30240}, 3}, {{30240, 10080}, 5}, {{10080, 1440}, 6}, {{1440, 0}, 13}}, {{{129600, 30240}, 15}, {{30240, 10080}, 15}, {{10080, 1440},9}, {{1440, ...


5

I'm assuming here that the OP's code have been evaluated so we can test if the following works. Thanks to george2079 this is the initially populated rows indices list. start = #1 (39 - #1)/2 - 18 & /@ Range[18]; {1, 19, 36, 52, 67, 81, 94, 106, 117, 127, 136, 144, 151, 157, 162, 166, 169, 171} I'm assuming we have rows referring to those ...


5

Assumptions are not used in normal evaluation, but only in certain functions like Simplify. Another, simpler example: In[1]:= $Assumptions = x \[Element] Reals Out[1]= x \[Element] Reals In[2]:= Conjugate[x] Out[2]= Conjugate[x] In[3]:= Simplify[%] Out[3]= x You see, during normal evaluation Mathematica doesn't recognize that x is supposed to be ...


4

L = 10; First of all you could get Booolian array simply as (thx. to @Kuba) RandomInteger[1,{L,L,L}] But if you are interested in thresholding: M = RandomReal[{0, 1}, {L, L, L}]; First of all do not binarize procedurally, use functional style, say: bM = M /. x_ -> UnitStep[x - .5]; or image processing: bM = ImageData[Binarize[Image3D[bM], ...


3

An alternative is to recognize that the product of the eigenvalues is equal to the determinant. Hence: m = {{0.04 - 0.4 b, 0, 0.04 - 0.4 b}, {0, -0.08 - 1.2 b, -0.06 - 0.9 b}, {1.04 - 0.4 b, 2.08 - 0.8 b, 0}}; Roots[Det[m] == 0, b] Since the Det is a 3rd order polynomial, there are three zeros, which occur when b == 2.6 || b == 0.1 || b == ...


3

Well, this gives a polynomial answer: determinante = N@Expand@Det[SetPrecision[M15x15, Infinity]] (* -8.85105*10^55 - 5.50608*10^69 x + 2.79901*10^80 x^2 - 5.66691*10^90 x^3 + 3.30477*10^100 x^4 + 4.27517*10^110 x^5 - ... 7.20261*10^254 x^51 + 4.72779*10^252 x^52 + 6.39829*10^250 x^53 - 4.74757*10^247 x^54 - 4.47661*10^245 x^55 *) The ...


3

Another version using Subsets. I assume that the initially defined rows are stored in x, so: x = o[[{1, 19, 36, 52, 67, 81, 94, 106, 117, 127, 136, 144, 151, 157, 162, 166, 169, 171}]]; Then the full matrix is constructed with: o2 = Mean[x[[#]]] & /@ SortBy[Subsets[Range[18], {1, 2}], First]; o2 == o (* True *)


3

Another approach, maybe a little easier to understand: Construct an array of only the initially defined rows: initial = o[[#1 (39 - #1)/2 - 18]] & /@ Range[18] ; this table procedure makes use of the fact that your 'initial' rows are also the "average" of the row with itself..: Transpose@ Table[ Flatten@ Table[ (initial[[j, k]] + initial[[i, ...


3

Start with the n x n matrix f[n] given by (for example, belisarius' code): f[n_] := ArrayPad[{{x, y}, {z, x}}, {0, n - 2}, "Fixed"] + DiagonalMatrix[Join[{0}, ConstantArray[u - x, n - 1]]] And evaluate substitutions = { x -> {{0, 1}, {1, 0}}, y -> {{1, 1}, {1, 0}}, z -> {{1, 0}, {1, 1}}, u -> {{p, q}, {r, s}} } If ...


2

Apologies if I've misunderstood your questions. I've never used Dispatch before, as suggested by Kuba in the comments, but it seems to be the right tool for the problem if speed is your concern. First off, I hope it's clear that accessing the list corresponding to an index pair is as straightforward is applying the rules list for pattern replacement: rules ...


2

The following assumes that your replacements are 3x3 matrices but it is easy to generalize. I'm not sure if you need. It will take care of -1 on edges. replace[mm_, reps_] := Module[{m = ArrayPad[mm, 1], pos = Position[mm, -1]}, MapThread[ (m[[#[[1]] ;; #[[1]] + 2, #[[2]] ;; #[[2]] + 2]] = #2) &, {pos, reps}]; ArrayPad[m, -1]] mm = ...


2

Finally I got a feedback from Wolfram support on the AMD algorithm. It turned out that there is (almost as usual) an undocumented implementation of the AMD algorithm within Mathematica. The algorithm is exactly identical to the MATLAB implementation, thus exactly what I was looking for. By calling SparseArray`ApproximateMinimumDegree[m_Matrix] one gets ...


2

Your expression simplifies to this $$\vec X \vec X^T A + A^T \vec X \vec X^T$$ using just these rules Unprotect[D, Transpose, Dot]; (*Derivative rules*) D[Tr[A_], X_] := Tr[D[A, X]] D[Transpose[A_], X_] := D[A, X]\[Transpose] D[A_ .B_, X_] := D[A, X].B + A.D[B, X] (*Tranpose rules*) 0\[Transpose] := 0 1\[Transpose] := 1 (A_\[Transpose])\[Transpose] := A ...


2

I'll illustrate on a smallish matrix, using exact arithmetic. That should make it relatively easy to verify correctness. First we create a tridiagonal 5x5 matrix. n = 5; SeedRandom[33333]; mat = RandomInteger[{-100, 100}, {n, n}]; Do[mat[[i, j]] = 0; mat[[j, i]] = 0, {i, 3, n}, {j, 1, i - 2}]; mat (*Out[68]= {{-30, -98, 0, 0, 0}, {12, 72, 29, 0, 0}, {0, ...


2

There is an add-on package that's worth mentioning in this context, mainly to address Wouter's comment: in the Combinatorica package, you find some group-theory related commands that are not part of the System context to which the linked guide refers. One of them is ConstructTabelau, addressing the comment by Wouter. Sometimes the built-in gems are hard to ...


1

From the docs on AdjacencyMatrix: Rows and columns of the adjacency matrix follow the order given by VertexList And from the docs on VertexList: Vertices are taken in the order they appear in the list of edges. Thus, you have {VertexList[g1], VertexList[g2]} (* {{1, 2, 3, 4, 5, 6, 7, 8}, {1, 6, 7, 8, 2, 3, 4, 5}} *) So, you can give an ...


1

a machine precision symmetric matrix: n = 5; m = Nest[ Join[#, {Table[#[[i, (Length[#] + 1)]], {i, Length[#]}]~Join~ RandomReal[{-10, 10}, {n - Length[#]}]}] & , {} , n]; convert the matrix to an exact rational form, do the eignevector extraction and convert back to high precision floats: ev = N[Normalize /@ ...


1

Although the documentation could be clearer on this point, Eigenvectors doesn't like to work symbolically on a matrix containing elements with approximate numbers. The solution is to Rationalize the matrix. data = {{1.8741*10^7 + 1.40161*10^6 B, 2.79374*10^7}, {2.79374*10^7, -3.1235*10^7 - 1.40161*10^6 B}}; Eigenvectors[Rationalize[data]] // Column ...


1

The matrix Clear[a,B,d,j,M]; m = {{B/2 - d - j/2 + a, (Sqrt[2]*j)/2, M}, {(Sqrt[2]*j)/2, B/2 + a, 0}, {M, 0, (-3*B)/2 - d + j/2 + a}}; has eigenvalues determined by the characteristic polynomial of (maximal) degree 3. In the absence of any other information, we get three Root objects as the eigenvalues, which is Mathematica's way of preserving all ...


1

Seems like the problem is not solved completely in the previous post. For this problem, it is straightforward to obtain the positive semi-definite condition of S by Cholesky decomposition, which all the diagonal elements should be nonnegative. Diagonal[CholeskyDecomposition[S]] After some simplification, it can be shown the diagonal elements are {1/r, ...


1

These are ancient routines I have been using a long time ago. As a matter of fact, it's been so long that I do not even remember if I wrote them or simply shamelessly took them from some other source. Back at the time the only sources I had at my disposal where The Mathematical Journal (prior to 1998 or 1999), Bahder's wonderful book (which is the most ...



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