New answers tagged

2

Turns out you cannot do this using the built in function Orthogonalize. Rather you need to meld answers from two previous questions: The first here. The second here. Note: This function is opinionated at inserts 0 as the first value returned in the list. oneStepOrtogonalizeGen[vec_, {}, _, _, _] := vec; oneStepOrtogonalizeGen[vec_, vecmat_List, dotF_, ...


3

Here an example how to insert a row (would be easier with Insert: A = ConstantArray[0, {5, 6}]; row = ConstantArray[1, {1, 6}]; B = Join[A[[1 ;; 2]], row, A[[3 ;;]]]; B // Dimensions {6,6} Alternatively, you can use B = Insert[A, row, 3] Here an example how to insert a row (not that easy with Insert): A = ConstantArray[0, {6, 5}]; col = ConstantArray[...


0

Question: Does this MMA result mean the accepted answer is incorrect? Answer: Yes, if the question is "How to decompose a matrix into the outer product of two vectors". No, if the question is "find two vectors u and v, that minimize some difference from $M$". However, you can use the approach suggested to recover several pairs of vectors, whose outer ...


3

By using a sparse solver you can gain another factor of ten in speed over @rhermans' method: Eigenvectors[m // SparseArray // N, 1, Method -> "Arnoldi"] // AbsoluteTiming (* {0.001119, {{-0.0725514, -0.106358, -0.0986766, -0.110735, [...]}}} *)


13

That's an eigenvalue problem! How to see that? Well, let's define some example data: d = 3; H = N@DiagonalMatrix[Range[d]]; A = # + #\[Transpose] &@RandomReal[{-1, 1}, {d, d}]; Both numerator and denominator can be written as bilinear forms of the vector $\operatorname{vec}(A)$: Avec = Flatten[A]; To this end, we need the following matrices and ...


4

See if you can spot the difference between Mathematica and MATLAB: {qq, rr} = QRDecomposition[N[{{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}]] {{{-0.57735, -0.57735, -0.57735}, {0.617213, 0.154303, -0.771517}, {0.534522, -0.801784, 0.267261}}, {{-1.73205, -8.0829, -22.5167}, {0., -4....


4

As was noted by @HenrikSchumacher the first methods works in the desired way because the eigenvalues of the matrix d are evaluated "analytically", i.e. each eigenvalue is given as a function of the parameter \[Delta]. Therefore, the plot shows them as smooth functions of \[Delta]. In the second plot, where the eigenvalues are calculated from the eigenvectors ...


6

I have been asked to write down a Mathematica Code You could try displayRREF ? The latest version is at Find Elementary Matrices that produce RREF CurrentValue[$FrontEnd, {"PrintAction"}] = {"PrintToNotebook"} m = 4; mat = HilbertMatrix[m]; b = Table[Random[], {m}] displayRREF[mat, b] Compare to Mathematica: LinearSolve[mat, b] Inverse[mat] // ...


4

The issue is the Evaluate in Plot[Evaluate[Eigenvalues[d[\[Delta]]]], {\[Delta], -0.3, 0.3}] You certainly use this trick to get the coloring in Plot correct. However, with Evaluate[Eigenvalues[d[\[Delta]]]], you enforce symbolic computation of eigenvalues. The correct ordering for symbolic eigenvalues cannot be figured out until numerical values for \[...


1

One way to do this is to set up a matrix that is 1 where everything is the same and zero where different, then Total all the elements in the product and divide by how many there are to get the mean. For your example A and M: a = {{0, 1, 5}, {1, 0, 5}, {5, 5, 0}}; M = Array[m, {3, 3}]; sel = Union[Flatten[a]]; Table[t = Total[(1 - Abs@Sign[a - sel[[i]]]) M, ...


6

Here is one idea using Pick and Total. Setup: SeedRandom[123]; n = 3000; nedges = 12000; g = RandomGraph[{n,nedges}]; distmatrix=GraphDistanceMatrix[g]; m = RandomReal[{0.1,1}, {n, n}]; m = UpperTriangularize[m, 1]+Transpose[UpperTriangularize[m, 1]]; ones = ConstantArray[1, {n, n}]; distances = Union @ Flatten @ distmatrix {0, 1, 2, 3, 4, 5, 6, 7} ...


1

There are at least a few ways to improve matters. First is to use NullSpace[mat,Modulus->2] This is still memory hungry though. There is a splitting method, useful when the row count is large, that is shown here. Another method, which can be used in tandem with splitting, is to use bit strings to represent rows. The null space can then be extracted ...


4

There are plenty of optimization opportunities. For starters, here a way to compute all relevant values of V to 12 digits accuracy in one go -- and 100 times faster: c = 40.; L = 200; a = Sort@RandomReal[{-\[Pi], \[Pi]}, L]; b = Sort@RandomReal[{-\[Pi], \[Pi]}, L]; Vvector = Table[V[j, c, {a, b}], {j, 1, L}]; // AbsoluteTiming // First Vvectorfast = With[{...


7

ClearAll[f] f[x0_, y0_] := D[{Sqrt[x^2 + y^2], ArcTan[x, y]}, {{x, y}}] /. {x -> x0, y -> y0} f[0.3, 0.5] // MatrixForm I would caution you against using MatrixForm in the definition, as that would leave you with results that cannot be easily used in further computation.


1

You can write something like f[{r_, θ_}] := Module[{M = D[{Sqrt[x^2 + y^2], ArcTan[x, y]}, {{x, y}}]}, Block[{x = r Cos[θ], y = r Sin[θ]}, M]] I wouldn't be surprised if this has a slightly simpler formulation. The symbolic result agrees with what I expect: Assuming[r > 0, Simplify[f[{r, θ}]]] (* {{Cos[θ], Sin[θ]}, {-(Sin[θ]/r), Cos[θ]/r}} *) ...


Top 50 recent answers are included