Tag Info

Hot answers tagged

22

If you have Mathematica 10 you can use the new Inactive functionality step1 = MatrixForm[Inner[Inactive[Times], A, A, Inactive[Plus]], TableSpacing -> {3, 3}] step2 = Activate[step1, Times] Activate[step2]


12

You can use HoldForm or Defer with Composition if you are still using Pre V10 versions: MatrixForm[Inner[Composition[Defer, Times], A, A, Composition[Defer, Plus]], TableSpacing -> {3, 3}] MatrixForm[Inner[Times, A, A, Composition[HoldForm, Plus]], TableSpacing -> {3, 3}] MatrixForm[Inner[Times, A, A, Plus], ...


10

Here's an approach without If or For. First a helper function: (* Thanks to Belisarius for the mrow& suggestion *) g[x_] := NestWhile[mrow&, x, MemberQ[x - #, 0] &] Then: NestList[g, mrow, 9] // MatrixPlot Where mrow is as you've defined it in the question.


10

Using Composition I can apply RotationTransform, TranslationTransform , ShearingTransform one after the other. Graphics3D[{ Opacity[1] , Red , Arrow[{{0, 0, 0}, {1, 0, 0}}] , Green , Arrow[{{0, 0, 0}, {0, 1, 0}}] , Blue , Arrow[{{0, 0, 0}, {0, 0, 1}}] , Opacity[0.2] , GeometricTransformation[Cuboid[-{1, 1, 1}/4, {1, 1, 1}/4], ...


9

Grid directly supports such lines, called Dividers: m = augmentedMatrix[6]; g = Grid[m, Dividers -> {7 -> {Red, Dashed}}] All that remains is to incorporate the large ( ) brackets used by MatrixForm: MatrixForm[{{g}}] Another approach is to realize that both MatrixForm and Grid produce a GridBox expression: Shallow[ToBoxes @ MatrixForm[m], ...


7

This is not a matter of "force". A Root object represents the exact root of a polynomial that cannot be represented exactly in closed form, or (in the case of cubics and quartics) cannot be represented succinctly. It is not "unsolved"; it is just a way of writing something that is hard or impossible to write down otherwise. If you want to convert cubic or ...


6

(Updated to show no mesh.) The data seems to have been converted from polar coordinates. One can convert it back and interpolate, with an appropriate interpolation order. Below I show orders 1 and 3 (3 is the default). polardata = {{#4, #3}, Norm[{#1, #2}]} & @@@ Transpose[{ Flatten[xx], Flatten[yy], Flatten[zz], Flatten@ ...


6

mat = {{2, 1, 0}, {3, 0, 1}, {4, 2, 1}, {2, 0, 3}, {1, 0, 0}, {0, 0, 1}, {3, 3, 2}, {0, 2, 1}, {0, 1, 1}, {2, 1, 2}}; rules = {0 -> 1000 ,1-> 11, 2-> 22, 3 -> 33, 4-> 44}; mat[[All, -1]] = mat[[All, -1]] /. rules; mat (* {{2, 1, 1000}, {3, 0, 11}, {4, 2, 11}, {2, 0, 33}, {1, 0, 1000}, {0, 0, 11}, {3, 3, 22}, {0, 2, 11}, {0, 1, ...


6

SeedRandom@0; mat = RandomInteger[{0, 10}, {2, 3, 3}]; MatrixForm@List@Grid[List@(TableForm /@ mat), Dividers -> {2 -> Directive[Red, Dashed]}] Of course you can play with spacings: TableForm[#, TableSpacing -> {1, 1}] & /@ mat To go a bit further with Dividers: SeedRandom@0; mat = RandomInteger[{0, 10}, {10, 3, 3}]; ...


5

x = {TCC12, TCC12, B96, TM12, TCC12, B96}; x /. {a___, b_, b_, c___} :> {a, b, c} {TCC12, B96, TM12, TCC12, B96} First /@ Split[x] Same output, but probably faster. Update thanks to Belisarius (m = {{1, 1, 1, 1}, {2, 2, 0, 2}, {0, 1, 0, 0}, {2, 2, 0, 0}}) // MatrixForm Map[First, Split /@ m, {2}] // MatrixForm


5

Could look for a counterexample using FindInstance. tmat = {{t11^2, t11*t12}, {t11*t12, t12^2 + t22^2}} - IdentityMatrix[2]; evals = Eigenvalues[tmat]; FindInstance[(evals[[1]] <= 0 || evals[[2]] <= 0) && t11^2 >= 1 && t22^2 >= 1, Variables[tmat], Reals] (* Out[237]= {{t11 -> Sqrt[2], t12 -> 1, t22 -> ...


5

The eigenvalues are Eigenvalues[{{t11^2, t11*t12}, {t11*t12, t12^2 + t22^2}} - IdentityMatrix[2]] giving {1/2 (-2 + t11^2 + t12^2 + t22^2 - Sqrt[ t11^4 + 2 t11^2 t12^2 + t12^4 - 2 t11^2 t22^2 + 2 t12^2 t22^2 + t22^4]), 1/2 (-2 + t11^2 + t12^2 + t22^2 + Sqrt[ t11^4 + 2 t11^2 t12^2 + t12^4 - 2 t11^2 t22^2 + 2 t12^2 t22^2 + ...


4

You can use matrix[[#, #2 ;; #3]] & @@@ triplets A 20 by 10 example: matrix = RandomInteger[10, {20, 10}]; matrix // TableForm triplets = Flatten/@Transpose[{RandomInteger[{1, 20}, {8}], Sort/@RandomInteger[{1, 10}, {8, 2}]}] {{14, 5, 10}, {11, 4, 10}, {2, 2, 10}, {10, 8, 10}, {12, 3, 9}, {3, 3, 5}, {6, 4, 7}, {5, 5, 10}} matrix[[#, #2 ;; ...


4

I think the analogue of Matlab's implicit concatenation is ArrayFlatten, but it still needs to be called explicitly. (aa = Table[a[i, j], {i, 3}, {j, 3}]) // MatrixForm $$\left( \begin{array}{ccc} a(1,1) & a(1,2) & a(1,3) \\ a(2,1) & a(2,2) & a(2,3) \\ a(3,1) & a(3,2) & a(3,3) \\ \end{array} \right)$$ (bb = Table[{b[i]}, ...


4

A simpler approach: {m, n} = Dimensions[xx]; fx = Interpolation[Flatten[Table[{{i, j}, xx[[i, j]]}, {i, m}, {j, n}], 1]]; fy = Interpolation[Flatten[Table[{{i, j}, yy[[i, j]]}, {i, m}, {j, n}], 1]]; fz = Interpolation[Flatten[Table[{{i, j}, zz[[i, j]]}, {i, m}, {j, n}], 1]]; ParametricPlot3D[{fx[i, j], fy[i, j], fz[i, j]}, {i, 1, m}, {j, 1, n}, PlotPoints ...


4

The OP's listParametricPlot3D constructs nonplanar quadrilaterals (Polygons) for a GraphicsComplex with Polygon[Flatten[ Table[{1 + i + xx j, 2 + i + xx j, 2 + i + xx (j + 1), 1 + i + xx (j + 1)}, {j, 0, yy - 2}, {i, 0, xx - 2}], 1]] where xx, yy are the dimensions of the tensor grid for the surface in the OP's data. One problem with nonplanar ...


4

mat[[All, -1]] = Transpose[mat][[-1]] /. rules; mat {{2, 1, 1000}, {3, 0, 11}, {4, 2, 11}, {2, 0, 33}, {1, 0, 1000}, {0, 0, 11}, {3, 3, 22}, {0, 2, 11}, {0, 1, 11}, {2, 1, 22}}


4

Let me reconstruct your Vandermonde matrix: A = Outer[Power, Range[10], Range[0, 3]]; A // MatrixForm Then there are two possibilities to compute SVD: Analytic expressions Numerical values Your input is the integer array so Mathematica choose the first one and try to give your the answer in an analytic form. It returns the result as roots of the ...


4

The magical words are Singular Value Decomposition. The singular vectors corresponding to small singular values form the kernel. Of course, Singular Value Decomposition is available in Mathematica as SingularValueDecomposition[]. As confirmed by Daniel Lichtblau, the built-in Tolerance option to NullSpace[] does it this exact way.


4

RandomVariate[NormalDistribution[], {r, r}] does not give you normalized eigenvectors. To obtain an orthonormal basis, you can first generate a random matrix, and then apply Orthogonalize to it. Following is the correct code. r=4;(*matrix dimension*) dom={1,10};(*domain of random numbers*) eig=DiagonalMatrix[-RandomInteger[dom,r]] (*eigenvalues in diagonal ...


3

Here are a couple of ways: Cases[mat, {e__, l_} :> {e, l /. rules}] or ReplacePart[mat, {i_, 3} :> (mat[[i, 3]] /. rules)]


3

Nice question. I'd try to do something with recursion instead, like Clear[f]; f[n_] := f[n] = newRow[f[n - 1]] f[0] = ConstantArray[10, 10]; newRow[previousRow_] := With[{row = mrow}, If[MemberQ[previousRow - row, 0], newRow[previousRow], row] ] Array[f, 10] // MatrixPlot


3

If the rule doesn't fit, change it: rules = {a_, b_, #} :> {a, b, #2} & @@@ {0 -> 1000, 1 -> 11, 2 -> 22, 3 -> 33, 4 -> 44}; mat /. rules {{4, 4, 1000}, {4, 1, 1000}, {1, 2, 33}, {3, 1, 1000}, {2, 0, 33}, {4,3, 33}, {2, 1, 11}, {2, 0, 44}, {3, 3, 22}, {1, 2, 22}}


3

you still can use MapThread. consider the example given by kguler: MapThread[matrix[[#, #2 ;; #3]] &, Transpose[triplets]]


3

Table and MapAt with Span can reduce the code to almost two lines: n = 3; A = RandomInteger[10, {n, n}]; MatrixForm[A] LU = Join[A, IdentityMatrix[n], 2]; res = Table[{LU = MapAt[#/LU[[k, k]] &, LU, k], LU = MapAt[# - #[[k]] LU[[k]] &, LU, k + 1 ;;]}, {k, n}]; Map[augmentedMatrixForm, res, {2}] // Grid With "tags" it is a bit longer LU ...


3

Update Another try arrow = Graphics[{Arrowheads[Small], Arrow[{{0, 0}, {6, 0}}]}, ImageSize -> {50,10}]; product[m_, n_] := Module[{s, t}, {{Subscript[r, n]/m[[n, n]]}, t = MapAt[#/m[[n, n]] &, m, n], Table[ s = Subscript[r, i] - t[[i, n]] Subscript[r, n]; t = MapAt[# - t[[i, n]] t[[n]] &, t, i]; s, {i, n + 1, Length[m]}], t} ...


3

Perhaps this will work for you. Given a symbol, say t, and a matrix, say m, it will define a set of indexed variables t[1], t[2], ..., t[n], bound to the respective rows of m. SetAttributes[assign, HoldFirst]; assign[name_Symbol, matrix_List] := ( Clear @ name; Do[t[i] = matrix[[i]], {i, 1, Length@matrix}] ) Generate some data. SeedRandom[42]; m ...


3

The code as below can achieve the result that you need. Clear@t; mat = RandomInteger[{1, 10}, {20, 4}]; Evaluate[t /@ Range[Length@mat]] = mat Because of (=)Set has the attribute HoldFirst, I use the function Evaluate to evaluate first before proceeding with Set.


2

exp = (a A + a B) /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}}; exp[[1, 1]] The original code takes part [[1,1]] of the expression which is a, hence 2. Alternatively you could put parentheses around expression and rules and take part or Part[(a A + a B) /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}}, 1, ...


2

Although I prefer kguler's method I don't want to be left out of the fun therefore: Cases[triplets, {r_, c1_, c2_} :> matrix[[r, c1 ;; c2]]]



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