Hot answers tagged

6

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] := ...


5

Something like that? The initial matrix (general case): mat = Array[d, {30, 30}]; mat // MatrixForm Gives: Then: vec = Flatten[mat]; {vec} // MatrixForm And finally: bigmat = Transpose[{vec}].{vec}; Checking: bigmat[[1]] bigmat[[;; , 1]] Diagonal[bigmat]


5

Symbolic evaluation (if you only need some of the elements of the matrix, use this). mat[row_, col_] := d[Ceiling[row/30], Ceiling[col/30]] d[Mod[row, 30, 1], Mod[col, 30, 1]] For instance: mat[50, 80] (* d[2, 3] d[20, 20] *) If you want the actual matrix, just do: matrix = Array[mat, {900, 900}] EDIT: If you must use a loop (which is slower), ...


4

Set your matrix and take the eigensystem: a = {{5, 0.1, 0.1}, {2, 60, 1}, {1, 0, 9}}; {eigVal, eigVec} = Eigensystem[a]; Find the max values in each eigenvector, and find their positions in order: maxes = Max /@ Abs[eigVec]; ord = Flatten@Table[Position[Abs[eigVec[[i]]], maxes[[i]]], {i, Length[eigVal]}] {2, 3, 1} Then use the ordering to permute the ...


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]], ...


3

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

I think try to create a zero-matrix and add your matrix on it will be helpful, just like the following code shows. In[22]:= kglobal2 = Module[{sum = ConstantArray[0, {8, 8}]}, sum[[1 ;; 4, 1 ;; 4]] += k12; sum[[{1, 2, -2, -1}, {1, 2, -2, -1}]] += k14\[Transpose]; sum ] Out[22]= {{9.92, 4.08, -6.08, -1.52, 0, 0, -3.84, -2.56}, {4.08, 380450., -1....


1

This gives you the entries for such a matrix: mat = {{a, b}, {c, d}}; SolveAlways[CharacteristicPolynomial[mat, λ] == (λ - α) (λ - β), λ] However, it is probably preferable to choose mat such that it has only as many unknowns as the matrix dimension.


1

mat = {{1, 2, 3, 4}, {0, 1, 2, 1}}; With[{sum = Total@mat[[All, 2]]}, mat /. {a_, b__, _} :> {a, b, a/sum}] Read on patterns and transformation rules in help.


1

You can also use Span to achieve this m[[1 ;; 2, 4]] = m[[1 ;; 2, 1]]/Total[m[[1 ;; 2, 2]]]


1

Timing results in Mathematica 10.1.0 under Windows 7 x64: {0.0660777, Null} {0.0303608, Null} {0.190943, Null} {1.46382, Null} {1.41635, Null} {0.183233, Null} So I confirm MatrixExp[s1, v] and MatrixExp[s1, v, Method -> "Krylov"] as being slower on my system. ( Use this Community Wiki to share any other timing results of interest. )


1

Sort[MapThread[{First@Ordering[-Abs[#2], 1], #1} &, Eigensystem[A]]][[All, 2]] {4.97199, 60.0037, 9.02434}


1

Use RandomComplex[{-1 + -r*I, 1 + r*I}, {n^2, n^2}] instead of Table, generate a random n*n matrix is much faster than generate a random number n^2 times. MatrixExp[mat, v] equal to MatrixExp[mat].v, and MatrixExp[mat] will be use for many times. So you can store it to avoid repeating calculation. (because of the floating error, the result of MatrixExp[...


1

The matrix desired is at most rank two and can be easily expressed as the product of a matrix and its transpose. I will number the elements for convenience and assume that state > 1 (otherwise we have imaginary elements, which would require further thought). n = 3; v1 = Prepend[Array[a, n], 1]; v2 = Prepend[Array[0 &, n], Sqrt[state - 1]]; M1 = ...


1

Will this a-bit-complex code fullfill your need? arrayinsert[mat_, x_, y_] := With[{pre = ArrayFlatten@List@Riffle[#, Unevaluated@ConstantArray[0, {Length@#[[1]], x}]] & /@ mat}, ArrayFlatten[List /@ Riffle[pre, Unevaluated@ConstantArray[0, {y, Length@pre[[1, 1]]}]]]] ArrayPad[k12, {0, 4}] + arrayinsert[Partition[k14, {2, 2}], 4, 4] The key of ...


1

sparse[n_] := Module[{range, column, bands}, range = Range[8, 4 n - 4, 4]; column = Table[{i, 1} -> 2 (i - 1), {i, 2, n, 2}]; bands = Table[Band[{i, 2}] -> Drop[range, (i - 3)], {i, 3, n, 2}]; SparseArray[column~Join~bands, {n, n}]] Construction of sparse[1000] in 0.35 seconds. Update Drop in Band can be dropped since Band stops putting ...


1

What about Table[x[Max[i, j], Min[i, j]], {i, 1, 6}, {j, 1, 6}] // MatrixForm



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