Tag Info

Hot answers tagged

7

I've spotted three issues with your approach and posted code: Spectral clustering uses the eigenvectors associated with the $k$ smallest eigenvalues of the Laplacian, but your code is selecting those associated with the $k$ largest eigenvalues. You need to Transpose your Kvecs prior to passing them to ClusteringComponents. As currently written, you're ...


4

This gives a slight speed up (~40%) for me: stepcp = Compile[{{m, _Complex, 2}, {u, _Complex, 2}, {n, _Integer}, {l, _Real}}, Block[{ m2 = ConjugateTranspose@m, x = u, ut = Flatten@Transpose@u}, Join[{1.0}, Table[x = m.x.m2; Flatten[x].ut, {i, n - 1}]/(2 l)]]] I replaced the NestList with a more procedural approach, calculating the trace of the ...


2

As pointed out by MarcoB in the comments, one shouldn't use MatrixForm for calculations (check the question he referred to). As he suggested, this is the real reason Inverse doesn't evaluate. Also, in this case the matrix m is singular. You can easily check that by MatrixRank[m] which yields 2, and also by checking Det[m]==0. How to proceed with m being ...


2

Sorry, I don't know. Have you tried compiling to C? One point: you should define stepcp with Set (=) rather than SetDelayed (:=) or you recompile it every time you use it. SparseArray is a specialized format of the high-level Mathematica language. It is not supported by compilation. Many operations are optimized to work on sparse arrays, saving ...


1

I think the function you are looking for is CoefficientArrays; here is its documentation. Your system is quite complex so I will let you deal with its intricacies, but here is a demonstration on a toy example. Let's define a set of linear equations in $x$, $y$, and $z$: eqns = {2 x - y + 4 z == 12, 3 x + 2 y + z == 10, -y + z == 1}; The solutions of ...


1

In Mathematica Abs is a Listable function which means that it may be applied to a scalar, matrix, or tensor directly: m1 = {{1, -8, 3}, {-1, -7, 9}, {-1, 0, -9}}; Abs[m1] {{1, 8, 3}, {1, 7, 9}, {1, 0, 9}} UpperTriangularize works like this: UpperTriangularize[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] {{1, 2, 3}, {0, 5, 6}, {0, 0, 9}} Matrix product ...



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