Tag Info

Hot answers tagged

9

A simple solution with And, Xor and Mod: n = 41; Table[If[Abs[2 j - 1 - n] < i && Xor[Mod[Abs[2 j - 2 - n] - i, 3] == 0, 2 j > n + 1], 1, 0], {i, n}, {j, n}] // ArrayPlot The same for n = 333: To be more functional-style: j = ConstantArray[Range@n, n]; i = Transpose@j; UnitStep[i - 1 - Abs[2 j - 1 - n]] (1 + (1 - 2 ...


7

Short Version You can get Mathematica to convert WolframAlpha-style free-form input into a valid expression using CTRL+= or by starting an input expression with =: Note how Mathematica made sense of two alternative free-form expressions of the same thing, and converted each into the same valid expression involving the Dot operator. Longer Version: ...


7

As Gregory Rut mentioned, DiagonalMatrix already has built-in support for generating banded matrices from lists: Inner[DiagonalMatrix, RandomInteger[{0, 5}, #] & /@ {49, 50, 49}, {-1, 0, 1}] which yields the following (when ArrayPlot is applied):


7

diag = RandomChoice[CharacterRange["a", "z"], #] & /@ {49, 50, 49}; m = SparseArray[Inner[Rule, {Band[{1, 2}], Band[{1, 1}], Band[{2, 1}]}, diag, List]] MatrixPlot[m, Mesh -> True] Timings: for a 50X50 matrix the timings of two methods based on Band and DiagonalMatrix are both 0. For larger matrices, Band is much faster: ClearAll[f1, f2]; f1 = ...


6

The closest I get is this MatrixPlot@ Table[Boole@((Divisible[Abs[k - n], 3] || k >= 22) && (Divisible[Abs[-22 + k + n], 3] \[Implies] k < 22) && n > 2 Abs[-22 + k]), {n, 41}, {k, 41}]


6

If you were to allow CellularAutomaton I think the simplest change is to drop every other row and column: MatrixPlot[CellularAutomaton[57, {{1}, 0}, 80][[;; ;; 2, ;; ;; 2]], ImageSize -> 400, Mesh -> All, PlotTheme -> "Monochrome"] There is however a discontinuity in the center compared to your original. I'll start working on other options. ...


6

You have to be a bit careful here; your last approach does not give the desired matrix F: (LinearSolve[dV, dv] // Transpose).dV === dv False Then what does give the correct output? We can use the fact that for generic matrices $A$ and $B$ we have $A.B = (B^T.A^T)^T$ and write F = Transpose @ LinearSolve[Transpose @ dV, Transpose @ dv] And indeed, ...


5

Here is my expanded response to kguler. I noticed that usually Band is less effective then DiagonalMatrix@SparseArray or manual constructing of the resulting SparseArray f1 = SparseArray[Inner[Rule, {Band[{1, 2}], Band[{1, 1}], Band[{2, 1}]}, #, List]] &; f2 = Inner[DiagonalMatrix, #, {1, 0, -1}] &;; f3 = Inner[DiagonalMatrix[SparseArray@#, #2] ...


4

Dot is a special case of Inner list = {{0, 1}, {0, 2}, {0, 3}}; Inner[Times, list, Transpose[list], Plus] // MatrixForm list = {{1, 1}, {1, 2}, {1, 3}} Inner[Power, list, Transpose[list], Plus] // MatrixForm Also possible: Outer[Times, {1, 2, 3}, {1, 2, 3}] // MatrixForm


4

If you are looking for matrix multiplication, use . (or the Dot command).


3

sundat = {{280., 0.082}, {280.5, 0.099}, {3995., 0.0087}, {4000., 0.00868}}; conversionfactors = {2., .5}; data2 = Transpose[conversionfactors Transpose[sundat]] or data2 = conversionfactors # & /@ sundat both give (* {{560.,0.041},{561.,0.0495},{7990.,0.00435},{8000.,0.00434}} *)



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