# Tag Info

8

Avoiding exact calculation by using approximated numerical value before calculation speeds things up. I'm also calculating only the first Eigenvectors as pointed pot by @Öskå. Now it takes only 15 milliseconds time AbsoluteTiming[Chop@Eigenvectors[N[m], 1, Quartics -> True]] {0.015600, {{-0.0725514, -0.106358, -0.0986766, -0.110735 [...] }}}

6

Perhaps MatrixLog[ m ] / Log[2]

6

Here is one way to see what is happening: z1 = Table[A.({rd[[i]]}\[Transpose].{rd[[i]]}), {i, 1, dim}]; // AbsoluteTiming z2 = Table[(A.{rd[[i]]}\[Transpose]).{rd[[i]]}, {i, 1, dim}]; // AbsoluteTiming which explicitly groups the calculations using parenthesis. As you found, z1 is slower than z2, which makes sense because z1 is essentially the product of ...

5

You could try this, which is straightforward: A = {{0.5, 1}, {2, 3}}; MatrixQ[A, IntegerQ] (* False *) Or alternatively - still pretty readable though! ArrayQ[A, _, IntegerQ] (* False *) This has the added bonus of being applicable to other arrays, for example: integerMatrix = RandomInteger[10, {10, 10, 10}]; ArrayDepth@integerMatrix (* 3 *) ...

5

Another way is to use ListConvolve: neighbors = ListConvolve[{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, m, {2, 2}, 0]; neighborCount = ListConvolve[{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, ConstantArray[1, Dimensions@m], {2, 2}, 0]; neighbors/neighborCount == MeanFilter[m, 1] True However, for speed it's not so good to go over the entire matrix in order to ...

5

Take the 2 by 2 case: {{a11,a12},{a21,a22}}.{x1,x2}={b1,b2}. If x and b are known and a is unknown, you can reformulate the problem to look like this: {{x1,x2,0,0},{0,0,x1,x2}}.{a11,a12,a21,a22}={b1,b2}. Now it is in the form where you can apply Solve or LinearSolve to find the a. Of course the answer will not be unique. In this case an answer is x = {{x1, ...

4

You can use CoefficientArrays: xx = {a[0, 0], a[0, 0] + a[1, 0] + a[2, 0] + a[3, 0], a[0, 0] + a[0, 1] + a[0, 2] + a[0, 3], a[0, 0] + a[0, 1] + a[0, 2] + a[0, 3] + a[1, 0] + a[1, 1] + a[1, 2] + a[1, 3] + a[2, 0] + a[2, 1] + a[2, 2] + a[2, 3] + a[3, 0] + a[3, 1] + a[3, 2] + a[3, 3], a[1, 0], a[1, 0] + 2 a[2, 0] + 3 a[3, 0], a[1, 0] + a[1, ...

4

The suggestions bar tries to offer a useful set of follow-up operations based upon the type of a result. In the case at hand, the result is a list of lists. But it so happens that all of the sublists are the same length, which happens to be the representation of a matrix in Mathematica. So the suggestions bar has guessed that the user has a matrix in mind ...

4

Perhaps this example matrix = RandomInteger[{0, 2}, {3, 3}]; matrix // MatrixForm which displays thiis 0 0 2 1 0 2 0 0 1 Then this matrix /. v_ /; v == 0 -> "" // MatrixForm which displays this 2 1 2 1 EDIT/Append I saw you revised your question after I posted the above. Perhaps you can adapt this: StringJoin[Flatten[Table[ ...

3

One way is to start with empty matrix. Add the first column. Then loop, each time adding the next column, and checking if the rank of this matrix has increased from before, if so, keep it, else skip over to the next column. Keep doing this until you reach the last column in the original matrix, or have collected m columns, where m is the rank of the original ...

3

If RowReduce won't help, then perhaps I don't know what you're looking for. Here's my understanding of the question in which I use RowReduce to get the answer. Example A random matrix: SeedRandom[1]; mat = RandomSample[#~Join~Accumulate@RandomSample[#, 2] &@ RandomInteger[{-5, 5}, {35, 37}]]; MatrixRank[mat] (* 35 *) We can use the ...

3

ClearAll[a, b, c, x, y, z, list, func]; list = {{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}}; func[x_, y_, z_, a_, b_, c_] := {a, b, c}.{x, y, z} func[##, a, b, c] & @@ list[[1]] (* a x1+b y1+c z1 *) func[## & @@ #, a, b, c] &@list[[1]] (* a x1+b y1+c z1 *) func[##, a, b, c] & @@@ list (* {a x1+b y1+c z1,a x2+b y2+c z2,a x3+b y3+c z3} *) ...

3

matrix2x2 (* {{{a1, a2}, {b1, b2}}, {{c1, c2}, {d1, d2}}} *) Map[Hold, matrix2x2, {2}] (* {{Hold[{a1, a2}], Hold[{b1, b2}]}, {Hold[{c1, c2}], Hold[{d1, d2}]}} *) And so: ReleaseHold[Map[Hold, matrix2x2, {2}].Map[Hold, matrix2x2, {2}]] (* {{{a1^2 + b1 c1, a2^2 + b2 c2}, {a1 b1 + b1 d1, a2 b2 + b2 d2}}, {{a1 c1 + c1 d1, a2 c2 + c2 d2}, {b1 c1 ...

3

There are a number of things that are going wrong here, and I'm not sure where to start: You do not have any continuously valued functions. You have simply defined six symbols, x1[0] through x2[2]. You cannot integrate x1[i] or x2[j] with respect to i or j because these symbols are not functions of i and j -- they are only defined for integer values. Maybe ...

2

I would approach this specific straightforward example in a straightforward way. Eliminate your matrix using RowReduce[mm]; red=RowReduce[mm]]; red//MatrixForm $\begin{pmatrix} 1 & 0.&0.&0.&0.&0.&0.&0.&0.&0.&\\ 0 & 1 &0.&0.&0.&0.&0.&0.&0.&0.&\\ 0 & 0 &1 ... 2 Change rows and columns to taste. rows = 2; columns = 3; matr = RandomReal[{10^-12, 10^-6}, {rows, columns}]; (matr2 = Table[Row[{ "matrix(", i, ",", j, ") = ", FortranForm[matr[[i, j]]]}], {i, Length[matr]}, {j, Length[matr[[1]]]}] // Flatten) // Column 2 building on @rcollyer's answer: The main improvement here is we print the list of elements in a way that the whole list can be copied at once. (also handle arbitrary dimensions automatically ) SetAttributes[fortranprint, HoldFirst] fortranprint[array_Symbol] := fortranprint[array, SymbolName[Unevaluated[array]]]; fortranprint[array_, name_] := ... 2 There is no subtlety to this, but it works: Table[i j, {i, 5}, {j, 5}] MapIndexed[Print["a(", #2[[1]], "," , #2[[2]], ") = ", #1] &, %, {2}]; 2 mat = {{{1, 0.4, 0, 0, 0, 0}, {2, 0.5, 0, 0, 0, 0}, {3, 0.2, 0, 0, 0, 0}}, {{3, 0.2, 1, 5.5686, 23.618, 1}, {2, 0.5, 0, 0, 0, 0}, {1, 0.4, 0, 0, 0, 0}} , {{2, 0.2, 0, 5.5686, 23.618, 1}, {3, 0.5, 0, 0, 0, 0}, {1, 0.4, 0, 0, 0, 0}}}; You can use #[[Ordering[#]]] & /@ mat or Sort /@ mat or Map[Sort, mat] all give (* { {{1, ... 2 You can also use a more "mathy" approach: Assuming xx and alpha are defined as in kguler's answer, A = D[xx, {alpha}] which produces identical output. I like thinking in this way because it is useful for computing hessians (in a slightly different context). 2 per = Permutations[Range[1, 9]]; all = (Det[{{#1, #2, #3}, {#4, #5, #6}, {#7, #8, #9}}] &) @@@ per; now: maxdet = Max[all] (*412*) positions of these matrices are: pos = Flatten@Position[all, maxdet]; (*{14176, 18520, 27624, 31968, 55210, 64000, 68658, 77448, 100690, 105034, 114138, 118482, 125216, 131000, 151265, 157001, 164810, ... 2 L = StringSplit["I want to create a matrix by laying"] {"I", "want", "to", "create", "a", "matrix", "by", "laying"} Outer[f, L, L] // TableForm 1 It is not clear why you need special functions to do what you want instead of using Drop. I think you should provide a minimum working example of your starting "matrix of matrix" and what you want the end result to be. In any case try this: m = Array[FromDigits[{##}] &, {3, 3, 4}] Drop[m, {2}] // MatrixForm Drop[m, None, {2}] // MatrixForm Edit ... 1 There are a number of errors in your code, so hopefully going through them one by one will help you in your task. First, I'll define numbers to insert into the matrices: h[k_, l_] := k Sin[l]; g[i_, k_, l_] := 10/(1 + i^2 + k^2 + l^2) + RandomReal[]; f[i_, l_] := i l; x[l_] := 1; M = 10; n = 4; The first line of code, H = Table[H[k, l], {k, 2 M}, {l, 2 ... 1 Perhaps this is a way: am = IdentityMatrix[3]; cm = {{c, c, c, c, c}, {d, d, d, d, d}, {e, e, e, e, e}}; dm = IdentityMatrix[5] ArrayFlatten[ Normal[SparseArray[{{1, 1} -> w[am], {1, 6} -> w[cm], {6, 1} -> w[Transpose@cm], {6, 6} -> w[dm]}, {6, 6}]] /. w -> Sequence] // MatrixForm where w is just a wrapper to allow ... 1 Use a Table iterator along the lines of Table[..., {i, 2, n}, {j, i - 1}] Notice that the bounds of j depend on i. 1 You could also use Export to export to a file directly. Or use CopyToClipboard : matr = RandomReal[{10^-12, 10^-6}, {4, 6}]; matr2 = Table[FortranForm[matr[[i, j]]], {i, 4}, {j, 6}]; matr3 = ExportString[ Flatten@Table[ "matrix(" <> ToString[i] <> "," <> ToString[j] <> ") = " <> ToString[matr2[[i, j]]], {i, ... 1 Since you are comfortable with the Kronecker product, you might also be interested in the command Outer which can be used quite succinctly in this setting: z = {1, 0}; o = {0, 1}; p = Flatten[Sin[t]*KroneckerProduct[z, z, z] + Cos[t]*KroneckerProduct[o, o, o]]; mat = Outer[Times, p, p]; MatrixForm[mat] which gives the desired form. 1 One problem is you're assigning the matrix form to your variable. Put matrix form on after setting your variable, e.g. MatrixForm[p = mat] not p = mat // MatrixForm. z = {{1}, {0}}; o = {{0}, {1}}; MatrixForm[ p = Sin[t]*KroneckerProduct[z, z, z] + Cos[t]*KroneckerProduct[o, o, o]] MatrixForm[pt = Transpose[p]] r = p.pt; r // MatrixForm 1 There's special function for generating fortran-like forms: SetOptions[$Output, PageWidth -> 100] FortranForm[string] And certainly you can manage string manually. To insert new strings in the string you can write something like this: string = StringJoin[ToString /@ Range[1000]]; step = 10 StringInsert[string, "&&\n&&", Range[step, ...

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