# Tag Info

9

MapThread[Dot, {{A, B, C}, {X, Y, Z}}]

7

extractBDM[mat_?MatrixQ] := Pick[mat, #, 1] & /@ Values[ComponentMeasurements[ Image[MorphologicalTransform[Unitize[mat], "BoundingBoxes"]], "Mask", CornerNeighbors -> False]] /. {} -> Nothing Explanation I just treat the values as an image pixel.So our purpose is finding the connected component.Supose your list mat is ...

5

{a, b, c, x, y, z} = RandomReal[{0, 1}, {6, 2, 2}] bk = Dot @@@ Transpose@{{a, b, c}, {x, y, z}} jd = MapThread[Dot, {{a, b, c}, {x, y, z}}] bk == jd (*True*) One can also use Inner[Dot, {a, b, c}, {x, y, z}, List] but you need to wrap lists in Unevaluated: Inner[Dot, Unevaluated@{a, b, c}, Unevaluated@{x, y, z}, List] See here for explanation.

5

Here's one way: ap = ConstantArray[0.001, {5, 10}]; b = {0.001, 0.005, 0.009, 0.01, 0.03, 0.05, 0.082, 0.1, 0.5, 1}; z = {{1, 3}, {2, 2}, {5, 7}}; f[ap_, {z1_, z2_}] := ReplacePart[ap, {z1, i_ /; i >= z2} :> b[[i]]] Fold[f, ap, z] (* {{0.001, 0.001, 0.009, 0.01, 0.03, 0.05, 0.082, 0.1, 0.5, 1}, {0.001, 0.005, 0.009, 0.01, 0.03, 0.05, 0.082, 0.1,...

5

One thing you might want to do is write the vector $\vec{a}$ as some magnitude $\theta$ times a unit vector {a1, a2, a3}. Then calculate $\exp(i \theta \,a\cdot\sigma)$. This will allow you to get rid of those factors of $\sqrt{a_1^2+a_2^2+a_3^2}$, which are just some $\theta$ anyway. Here it is in Mathematica:a = \[Theta] {a1, a2, a3}; b = a.Array[...

5

Here's something even more compact than my proposal in the comments: Standardize[RandomReal[1, {4, 4}], 0 &, Total] If you must have a left stochastic matrix where all the entries should be greater than a set value, you can do rejection sampling: keep generating a matrix as long as the smallest value is smaller than the cutoff: While[Min[sm = ...

4

I gave a presentation on one (efficient) way to do it at the 2009 tech conference. The essence is this function: matrixAssembly[ values_, pos_, dim_] := Block[{matrix, p}, SystemSetSystemOptions[ "SparseArrayOptions" -> {"TreatRepeatedEntries" -> 1}]; matrix = SparseArray[ pos -> Flatten[ values], dim]; SystemSetSystemOptions[ "...

4

Update-2: More compact version proposed by J. M. with the matrix normalized: steps = 3; (*order = 2^step*) h = Nest[Join[KroneckerProduct[#, {1, 1}], KroneckerProduct[IdentityMatrix[Length[#]], {1, -1}]] &, {{1}}, steps]; Orthogonalize[h] // MatrixForm Update-1: Creates un-normalized Haar matrix for $\text{order} = 2^n$. steps = 3; ...

4

yourlist = {a, b, c}; mat = ReplacePart[Outer[Times, #, #]&@Prepend[yourlist, 1], {1, 1} -> state] Change yourlist to the list of your interest. Or, taking @mikado 's idea of symbolically diagonalizing: matfunc[1, 1] = state; matfunc[1, a_Integer] := yourlist[[a - 1]]; matfunc[a_Integer, 1] := yourlist[[a - 1]]; matfunc[a_Integer, b_Integer] := ...

3

I think for this kind of matrix it is better to use some of the dedicated matrix formats, like, "MTX" (of Matrix Market) or "HarwellBoeing". Below are two examples using "MTX": one with a dense 6000x6000 matrix and one with a sparse matrix. Dense matrix Mathematica mat = RandomReal[{0, 1}, {6000, 6000}]; Export["/path/RandomMat.mtx", mat, "MTX"] Python ...

3

SetDirectory[NotebookDirectory[]] (mat = RandomReal[1, {5, 5}]) // MatrixForm Export["mat.txt", mat, "CSV"] Open python and type >python Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 >>> f = open ( 'mat.txt' , 'r') >>> mat = [ map(float,line.split(',')) for line in f ] >>> print(mat) [[0....

3

I am not sure if this is what you want (it would be helpful if you can give an example in your question). What I am doing here is to get the block matrix at any given position. First I create a general matrix. a = RandomInteger[{1, 9}, {2, 2}]; b = RandomInteger[{1, 9}, {3, 4}]; c = RandomInteger[{1, 9}, {2, 2}]; m = SparseArray[{Band[{1, 1}] -> a, Band[...

3

Your operation does not work because in this case it is not a matricial multiplication but a composition. Try mM = {{D[#, x] &, D[#, y] &}, {D[#, y] &, D[#, z] &}} v = {f[x, y, z], g[x, y, z]} apply[a_, b_] := Inner[#1[#2] &, a, b] This answer come from the article http://www.mathematica-journal.com/issue/v8i4/tricks/contents/...

3

Specify Eigensystem[h, 2, Method -> "Direct"] for both cases. That sparse array may go to a different solver (iterative) than the dense method. You can find more options in the documentation of Eigensystem under the options section.

3

Here is a neat way: Array[Function[n, {{n, 7 n - 2, 3, 2 n - 1}, {3, 4, n, 6 n - 1}, {9, 3, n, n - 3}, {n - 2, 1, 8, 7 n/3}}], 10, 1, Dot]

3

To verify that the rotations happen the way they're supposed to according to the documentation for EulerMatrix, you could use the following Manipulate: Clear[arrowAxes]; arrowAxes[arrowLength_: 1] := Map[{Apply[RGBColor, #], Arrow[Tube[{-#, #}]]} &, arrowLength IdentityMatrix[3]] Manipulate[ Graphics3D[{GeometricTransformation[arrowAxes[.7], ...

3

For the first part, you can use MatrixExp. Since you are interested in trigonometric form, I would suggest using polar coordinates from the beginning. p0 = PauliMatrix[0]; p1 = PauliMatrix[1]; p2 = PauliMatrix[2]; p3 = PauliMatrix[3]; a1 = a Sin[q1] Cos[q2]; a2 = a Sin[q1] Sin[q2]; a3 = a Cos[q1]; m = a1 p1 + a2 p2 + a3 p3; m1 = MatrixExp[I m] // ...

3

Use Part to subtract intensity and Transpose to align with the wavelength data: wavelength = Range[350, 750, (400/3647)]; withMagnet = Transpose[{wavelength, RandomReal[1, 3648]}]; withoutMagnet = Transpose[{wavelength, RandomReal[1, 3648]}]; (*The above code just simulates your imported data*) diff = Transpose[{withoutMagnet[[All, 1]], ...

2

Table[Table[ap[[z[[i, 1]], j]] = b[[j]], {j, z[[i, 2]], 10}], {i, 3}]; ap {{0.001, 0.001, 0.009, 0.01, 0.03, 0.05, 0.082, 0.1, 0.5, 1}, {0.001, 0.005, 0.009, 0.01, 0.03, 0.05, 0.082, 0.1, 0.5, 1}, {0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001}, {0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0....

2

I suppose you would like something like this? Select[A.B.Transpose[R].R.T, FreeQ[#, R] &] This mainly used the expression's tree like property. Due to Dot's Flat Property, the whole expression will actually looks like Dot[A,B,Transpose[R],R,T], thus this code can generate the result you want: A.B.T Note that I've change your C to T cause C is a ...

2

You can directly use the function pauliReduce that I defined in this answer: a = {a1, a2, a3} (* ==> {a1, a2, a3} *) a.{σ[1], σ[2], σ[3]} (* ==> a1 σ[1] + a2 σ[2] + a3 σ[3] *) pauliReduce[ MatrixExp[I a.{σ[1], σ[2], σ[3]}]] $$\frac{1} {\sqrt{\text{a1}^2+\text{a2}^2+\text{a3}^2}}\left(\hat{1} \sqrt{\text{a1}^2+\text{a2}^2+\text{a3}^2} \cos ... 2 Here's a quick-and-dirty method that does what (I think) you're after: makearr[{n_, m_}, p_] := Module[{base = PadLeft[ConstantArray[1, Round[n m p]], n m], cand}, While[(cand = ArrayReshape[RandomSample@base, {n, m}]; Max[Total[cand]] > n - 2 || Max[Total /@ cand] > m - 2)]; Position[cand, 1]]; Example usage: makearr[{5, 5}, .4] {{... 2 Like J.M. said, the use of ListConvolve can be a bit tricky, because by default it cuts overhangs and has no padding. From your description i guess you are more interested in something like this: MatrixPlot[ ListConvolve[GaussianMatrix[10], BoxMatrix[20] - DiamondMatrix[20], {1, -1}, {0, 0}] ] \mspace{172mu}\Big\Updownarrow \mspace{30mu} This ... 2 Use Simplify with Assuming: m = {{E^(I*β1 + I*β3) Cos[β2], E^(I β1 - I*β3) Sin[β2]}, {(-E^((-I) β1 + I*β3)) Sin[β2], E^((-I) β1 - I*β3)*Cos[β2]}}; MatrixForm[ Assuming[{β1, β2, β3} ∈ Reals, Simplify@ConjugateTranspose[m]]]$$\left( \begin{array}{cc} e^{i \text{$\beta$1}+i \text{$\beta$3}} \cos (\text{$\beta$2}) & e^{i \text{\$\...

2

In line with suggestion from @happy fish, I would write Energy = 1/2 (d1^2/2 + (-(d1/Sqrt[2]) + d2/Sqrt[2])^2) k - d1 P - d2 P - (d1^2/(2 L^2) + d2^2/(2 L^2)) P; d = {d1, d2}; ca = CoefficientArrays[Energy, d]; The list ca contains the term you are seeking, and satisfies ca[[1]] + ca[[2]].d + d.ca[[3]].d == Energy // Simplify Note that ca[[3]] is not ...

2

I'll give two solutions here: a not-that elegant solution which can apply to multiple sizes but all blocks MUST be Fully filled! (Just the limitations of Morphological methods) Function[{n}, Pick[mat, #, n] /. {} -> Nothing] /@ Range@Max@# &@ MorphologicalComponents[mat, Method -> "BoundingBox", CornerNeighbors -> False] This use ...

2

With Times: avec = Array[a, 4]; m = Outer[Times, avec, avec] /. {a[1] -> 1}; m[[1, 1]] = s; MatrixForm[m] Eigenvalues[m] Here a[2] is your a, a[3] is your b, etc. Change the 4 to 900 if you wish. There are two nonzero eigenvalues.

2

Reference: Part ListLinePlot[{myMatrix[[All,1]],myMatrix[[All,2]], ...}] data = {{1, 5, 10}, {1, 5, 10}, {1, 5, 10}, {1, 5, 10}, {1, 5, 10}}; ListLinePlot[{data[[All, 1]], data[[All, 2]], data[[All, 3]]}]] Or for a compact, universal solution (Courtesy of J.M.) ListLinePlot[Transpose[myMatrix]]

1

change your last two lines to: cT[{_, a2_, a3_}] := c11[m, n, a2, a3, F3, b]; cT /@ centroidList (*{80.1567, -95.8522, 0., 0., -80.1567, 95.8522, 0., 0.}*) Is this what you want?

1

You can do j=10; mat = Table[{{n, 7 n - 2, 3, 2 n - 1}, {3, 4, n, 6 n - 1}, {9, 3, n, n - 3}, {n - 2, 1, 8, 7 n/3}}, {n,j}]; Dot @@ Table[mat[[i]], {i,j}]//N Where j is the order to which you want to calculate the product, this gives as answer: {{7.28971*10^13, 1.09566*10^14, 7.92596*10^13, 2.71886*10^14}, {8.76822*10^13, 1.31681*10^14, 9....

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