# Tag Info

## New answers tagged linear-algebra

5

Iterating @J.M.'s comment: This problem has no exact solution. With[{ matrix = {{0.8111, 0.4867, -0.3244}, {a, b, 0}, {c, d, e}} }, Print[matrix.Transpose[matrix]]; Solve[ matrix.Transpose[matrix] == IdentityMatrix[3], {a, b, c, d, e} ] ] (* {{0.999995,... *) (* {} *) That is, the first column's first entry is not $1$, so there is ...

1

Not a full answer, but there are other tools available, such as Outer and TensorProduct. For example, compare AbsoluteTiming[(mat1 = Table[Etc[t] mtx, {t, 0., 20, 0.01}]);] with AbsoluteTiming[(mat2 = TensorProduct[Et[Range[0., 20, 0.01]], mtx]);] TensorProduct is over twice as fast. The answers are identical: Norm[Flatten[mat1 - mat2]] // Chop

5

EDIT My original post was unnecessarily complex (pun?) and I have taken the advice of Kuba. This is not really an advance but I post it for fun: v1 = {2, 1}; v2 = {-1, 1}; f[x_, y_] := {x, y}.{v1, v2}; Manipulate[ Row[{Show[Plot[{x, x^2, 5 Sin[x]}, {x, 0, 5}, PlotRange -> {0, 5}], ParametricPlot[{x, y}, {x, 0, 5}, {y, 0, 5}, MeshFunctions ...

8

I am writing this answer only to address the Wizard's comment of "not obvious". Recall that if you take two nonzero vectors $\mathbf v_1$ and $\mathbf v_2$ as your basis, you can then represent any other vector as a linear combination of these two ($x \mathbf v_1 + y \mathbf v_2$). In Mathematica, this is equivalent to the expression Transpose[{v1, v2}].{x, ...

2

Update As of Version 10 nonlinear control systems can be addressed by NonlinearStateSpaceModel. With this the answer given by @Suba Thomas can be obtained by: a1 = {{-3, 2}, {-0.25, 1}}; a2 = {{-1.9, -0.4}, {-2.24, -4.7}}; b1 = {{0.25}, {1}}; b2 = {{-2.5}, {1}}; c = {{1, 0.5}, {0, 1}}; ρ[1] = (1 - Tanh[x[1][t]])/2; ρ[2] = 1 - ρ[1]; xx = { x[1][t], ...

2

Using Smith Normal Form you can get two integer matrices with determinant 1 that would satisfy the equation $$X1.K.X2 = K_2$$ May be this is a good start you can use... resK = SmithDecomposition[K]; MatrixForm /@ resK resK2 = SmithDecomposition[K2]; MatrixForm /@ resK2 resK[[2]] == resK2[[2]] (* True *) K2 == ...

1

Perhaps this is a solution for the 2D case. lattice[basis : {Repeated[{_Real, _Real}, {2}]}, nX_Integer?Positive, nY_Integer?Positive] := Module[{box, sides}, box = Sort /@ Transpose[basis]; sides = Flatten[Abs[Differences[#]] & /@ box]; Flatten[CoordinateBoundsArray[box, sides, 0, {{0, nX - 1}, {0, nY - 1}}], 1]] With[{basis = {{1, ...

0

LatticeData["FaceCenteredCubic", "Image"] and try: LatticeData[#, "Image"] & /@ LatticeData[3]

0

The correct Mathematica code (v.10.2.0.0.) is: A = N[{{4, 1, -2, 2}, {1, 2, 0, 1}, {-2, 0, 3, -2}, {2, 1, -2, -1}}]; (*A=N[{{-42,43,-2,28},{43,-98,72,-26},{-2,72,-96,53},{28,-26,53,54}}];*) n = Length[A[[1]]]; zeroVector = {}; For[i = 1, i <= n, i++, zeroVector = Append[zeroVector, {0}]]; Alist = {A}; Hlist = {}; For[j = 1, j <= n - 2, j++, ...

10

Mr.Wizard proposed that the slowness is due to the copying of the data. It seems that this intuition is correct. We can use the two different arguments passing mechanism in LibraryLink to test this conjecture. In LibraryLink, there are the "copied" passing and the "shared" passing. The copied passing copies the data from Mathematica to the library function ...

4

The way I remember it from my Linear Algebra class is like this: Clear[b]; A = {{-1, 1, -1, 0, 0, 0}, {1, 0, 0, -1, -1, 0}, {0, -1, 0, 0, 1, -1}, {0, 0, 1, 1, 0, 1}}; bb = Array[b, Length@A]; Thread[NullSpace@Transpose@A . bb == 0] (* {b[1] + b[2] + b[3] + b[4] == 0} *) That is, the condition for a solution to A.x == b to exist is that b be in the ...

4

I believe that on packed arrays both Dot and Times are performed by external libraries, e.g. Intel MKL, and that following Mathematica's paradigm of immutability the library does not act directly upon the original array but rather a copy. I conjecture that this copying or transport is the cause of the slow-down that you observe and that within Mathematica ...

11

You can use Reduce[] to find a set of all conditions as follows: A = {{-1, 1, -1, 0, 0, 0}, {1, 0, 0, -1, -1, 0}, {0, -1, 0, 0, 1, -1}, {0, 0, 1, 1, 0, 1}}; b = {b1, b2, b3, b4}; x = {x1, x2, x3, x4, x5, x6} allConditions=Reduce[A.x == b, x] This returns b1 == -b2 - b3 - b4 && x3 == b2 + b3 + b4 - x1 + x2 && x5 == -b2 + x1 - x4 ...

3

So why the matrix number multiplication and addition so much slower than the matrix vector multiplication? Are there ways to speed them up? It seems that if we use SparseArray for this computation we can get ~3 times speed-up: n = 2000; tres = Table[ (Print[lth]; mtx = RandomReal[{0, 1}, {lth, lth}]; {lth, (AbsoluteTiming[ ...

2

Here are couple of quick tips. Lets say this is your matrix mat = SparseArray[{{i_, j_} /; Abs[i - j] == 3 -> 1, {i_, i_} -> 1}, {200, 200}]; This is the conventional way to find EigenSystem Eigensystem[SparseArray[{{i_, j_} /; Abs[i - j] == 3 -> 1, {i_, i_} -> 1}, {200, 200}]]; // AbsoluteTiming {53.6551, Null} Now just change the ...

10

First answer (extended comment actually) You have to define better your objective function. For example, the following works: ClearAll[mat, minev] SeedRandom[1] rm = RandomInteger[10, {40, 40, 3}]; mat[t_] := N[rm.{1, t, t^2}]; minev[t_?NumericQ] := First@Eigenvalues[mat[t], -1]; Take[Table[minev[t], {t, 0, 1, .01}], 3] (* {-0.864071 - 1.30548 I, ...

7

With[{x = Array[x, Dimensions[mA]]}, Solve[mA .x - x. mB + mC == 0, Flatten@x]] Or With[{x = Array[x, Dimensions[mA]]}, x /. Solve[mA .x - x. mB + mC == 0, Flatten@x]] {{{3, 1}, {0, 3}}}

0

If this is for convenience, then you could write a wrapped for JordanDecomposition, e.g. something like this: Clear[jd] jd[m_] := Module[{s, j}, {s, j} = JordanDecomposition[m]; {s, Inverse[s], j} ] Then for example: a = {{27, 48, 81}, {-6, 0, 0}, {1, 0, 3}}; jd[a] (* Out: { (* the similarity matrix s *) {{3, 18, 2}, {-3, -9, -(1/4)}, {1, 2, 0}}, ...

Top 50 recent answers are included