Tag Info

New answers tagged

0

matrix = Array[M, {3, 3}]; soln = {{M[1, 2] -> Cos[\[Psi][t]], M[1, 3] -> 0, M[2, 3] -> 0, M[3, 1] -> Cos[\[Theta][t]], M[3, 2] -> 0, M[3, 3] -> 1, M[2, 1] -> -Cos[\[Psi][t]] Sin[\[Theta][t]], M[2, 2] -> Sin[\[Psi][t]], M[1, 1] -> Sin[\[Theta][t]] Sin[\[Psi][t]]}}; matrix /. soln {{{Sin[[Theta][t]] ...


1

You can try NSolve since this is non-linear. But it might not be able to solve it. Find root can. Also, if you know range of solution expected, it might help. m = 3; A0 = RandomReal[{0, 1}, {m, m}]; B0 = RandomReal[{0, 1}, {m, m}]; x = {x1, x2, x3}; C0 = RandomReal[{0, 1}, m]; eq = Thread[A0.x + B0.Exp[x] == C0]; FindRoot[eq, {{x1, 0}, {x2, 0}, {x3, ...


1

Generally: Yes, as long as you actually give the matrices a and b, as well as the vector c. With their elements named as usual x={x1,x2} etc., you then just do: Solve[a.x + b.Exp[x] == c,{x1,x2}] Example: With a={{1,0},{0,1}}, b={{0,1},{1,0}}, c={c1,c2}, x={x1,x2} this will give you the solution: {{x1 -> -I \[Pi] + Log[-c2 + x2]}} i.e.: you are ...


0

There is something wrong here. Can you tell me how you happen to have a Dirac Matrices of $10^7 \times 10^7$, being almosssst Hermitian ? Your Hermitian or your not, there is no half Hermitian, or almost Hermitian. But anyway, there is one pretty simple way: Inverse[] function. And for this: " I'm sure that Mathematica is probably not capable of doing this ...


0

project euler 28 This is a pad version, padMatrix is written a bit complex. f[x_] := 1/4 (-1)^x (1 + 3 (-1)^x + 2 (-1)^x x) padMatrix[x_, pad_, type_: 0] := Which[type == 1, Append[x\[Transpose], pad]\[Transpose], type == 2, Append[x, Reverse@pad]\[Transpose], type == 3, Prepend[x, Reverse@pad], type == 4, Prepend[x\[Transpose], pad]] ...


0

I think you are looking for Replace: p4 - p5 == r45 i45 /. r45 -> 1 (* p4 - p5 == i45 *) % /. lhs_ == rhs__ -> rhs - lhs == 0 (* i45 + p5 - p4 == 0 *)


3

It depends on how PBS and the cluster environment are set up. Ideally, if cpuset support has been compiled in to PBS, and if you start Mathematica directly inside the PBS job, you should find that it uses all processors allocated by PBS (on that node--Eigensystem is not MPI-parallelized). If cpuset support isn't provided, then you risk starting as many ...


5

First a simpler way to get your first example: (m = ArrayFlatten[Transpose /@ {{v1, v2, v3}, {v4, v5, v6}}, 1]) // MatrixForm An alternative way to do @bill's undoing trick: (m2 = ArrayFlatten[Transpose /@ {{v1, ## & @@ Transpose[vNew]}, {v4, v5, v6}}, 1]) // MatrixForm Using ArrayReshape as an alternative to ArrayFlatten: ...


3

How about just breaking up the matrix and then reconstructing the same way. Here are your source vectors v1 = {1, 2, 3}; vNew = {{4, 5}, {6, 7}, {8, 9}}; v4 = {10, 11, 12}; v5 = {13, 14, 15}; v6 = {16, 17, 18}; So now define and reconstruct: {v2, v3} = Transpose[vNew]; ArrayFlatten[{Transpose@{v1, v2, v3}, Transpose@{v4, v5, v6}}, 1] // MatrixForm If ...


5

TL;DR; myArrayFlatten = Flatten /@ Flatten[#, {{1, 3}}] & {x,y,z} or {{x},{y},{z}} is considered column vector. Usage example: v1 = {1, 2, 3}; vNew = {{4, 5}, {6, 7}, {8, 9}}; v4 = {10, 11, 12}; v5 = {13, 14, 15}; v6 = List /@ {16, 17, 18}; { {v1, vNew, v1}, {v4, v5, v6, v1}, {vNew, vNew} } // myArrayFlatten // MatrixForm Flatten ...


1

A = {{0.1, 0}, {0, 0.1}}; B = {{2, 3}, {-3, 1}}; c = {{0.2, 0.6}, {0.2, 0}}; d = {2, 3}; e = {1, 0}; i = {{1, 0}, {0, 1}}; g[11] = {0, 0}; g[t_] := A.S[t+1].Inverse[i-B.S[t+1]].(B.g[t+1]-d)+A.g[t+1]+e; p[11] = {0, 0}; p[t_] := S[t].X[t] - g[t]; S[11] = {{0, 0}, {0, 0}}; S[t_] := c + A.S[t + 1].Inverse[i - B*S[t + 1]].A ; X[1] = {1, 0}; X[t_] := Inverse[i - ...


2

Seeing you asked about how to drop the first or last rows/columns, you can do that conveniently with Most and Rest: Most@m (* drops last row *) Most/@m (* drops last column *) Rest@m (* drops first row *) Rest/@m (* drops first column *)


5

Okay, following the "bare bones" approach for dropping rows and columns here are a few ideas. Starting matrix: m = Array[Times, {5, 6}] $\left( \begin{array}{ccccc} 1 & 2 & 3 & 4 & 5 \\ 2 & 4 & 6 & 8 & 10 \\ 3 & 6 & 9 & 12 & 15 \\ 4 & 8 & 12 & 16 & 20 \\ \end{array} \right)$ Part ...


2

A barebones example for the desired cropping is: m = Array[Subscript[a, ##] &, {4, 4}]; MatrixForm[m] $$\left( \begin{array}{cccc} a_{1,1} & a_{1,2} & a_{1,3} & a_{1,4} \\ a_{2,1} & a_{2,2} & a_{2,3} & a_{2,4} \\ a_{3,1} & a_{3,2} & a_{3,3} & a_{3,4} \\ a_{4,1} & a_{4,2} & a_{4,3} & a_{4,4} \\ ...


1

a = {{a1, a2}, {a3, a4}}; b = {{b1, b2}, {b3, b4}}; c = {{c1, c2}, {c3, c4}}; s[11] = {{0, 0}, {0, 0}}; s[10] = c + a.s[11].Inverse[IdentityMatrix[2] - b.s[11]].a which immediately returns {{c1, c2}, {c3, c4}} Trying to use upper case characters, like C, for variable names results in errors. Trying to use "abstract" vectors and matricies results in ...


2

With a = {{0.1, 0}, {0, 0.1}}; b = {{2, 3}, {-3, 1}}; c = {{0.2, 0.6}, {0.2, 0}}; i = {{1, 0}, {0, 1}}; and s[t_] := {{s11[t], s12[t]}, {s21[t], s22[t]}} one can see that s12 and s21 don't depend on t by evaluating c + a*s[t + 1]*Inverse[i - b*s[t + 1]]*a Therefore I set s[11] = {{0, 0.6}, {0.2, 0}} Redefining s with s[t_] := s[t] = c + a*s[t ...


2

mat = Table[i^2 + i j + j^3, {i, 4}, {j, 4}] Det[Drop[mat, {#}, {#}]] & /@ Range[Length@mat] {-36, -288, -252, -24} Timings for random 100X100 real and integer matrices: tstmat = RandomReal[100, {100, 100}]; (res1 = Det[Drop[tstmat, {#}, {#}]] & /@ Range[Length@tstmat]); // AbsoluteTiming // First (* 0.156253 *) (res2 = Diagonal@Minors[tstmat]); ...


0

Diagonal @ Minors[mat] (* {-24, -252, -288, -36} *)


0

A way to solve this is making the following change the fourth line into b = b /. {Subscript[be, 1] -> 1, Subscript[be, k_] :> (-1)*Subscript[be, k] /; k > 1} where we have taken the negative one out the Subscript function. This came from the kind comment by @bills that Subscript is mostly a formatting function whose output can become the ...


4

Using the built-in matrix manipulation commmands mat = Array[Subscript[a, ##] &, {4, 4}]; LowerTriangularize[mat] + Transpose[LowerTriangularize[mat]] - DiagonalMatrix[Diagonal[mat]] gives the same answer. This takes the lower triangular part and adds it to the transpose of itself, giving a symmetric matrix in which the diagonal entries have been ...


5

You could define it with Array[Subscript[a, Min[##], Max[##]] &, {4, 4}]


4

You can apply a rule using Condition: mat2 /. Subscript[a, i_, j_] :> Subscript[a, j, i] /; j > i giving $$\left( \begin{array}{cccc} a_{1,1} & a_{2,1} & a_{3,1} & a_{4,1} \\ a_{2,1} & a_{2,2} & a_{3,2} & a_{4,2} \\ a_{3,1} & a_{3,2} & a_{3,3} & a_{4,3} \\ a_{4,1} & a_{4,2} & a_{4,3} & a_{4,4} \\ ...


1

Try f[x_, y_] = Block[{x, y}, Assuming[x ∈ Reals && y ∈ Reals, Log[Det[V[x, y]\[ConjugateTranspose].V[x, y]]] /. e : Conjugate[EllipticTheta[a_, z_, q_]] :> EllipticTheta[a, Conjugate[z], q] // Simplify ] ]; Chop[N[Q[1, 1]]] (* 2.10739 *)


3

Use Transpose function, it would be like: ListPlot[Transpose[{row,col}]]


0

This can be handled by Solve straightforwardly: r = RandomInteger[{-10, 10}, {2, 2}]; a = {{a1, 0}, {0, a2}}; b = {{b1, b2}, {b1, b2}}; c = {{c1, c1}, {c2, c2}}; Solve[r.a + b == c, {a1, a2, b1, b2, c1, c2}] {{a2 -> 18 a1, b2 -> -45 a1 + b1, c1 -> -9 a1 + b1, c2 -> 9 a1 + b1}} You can interpret this as saying that for any a1 and b1, the other ...


0

Please check your definitions. You use e1 and eg. Here is what I think you're asking: M[t_] := {{Sin[t], Cos[t]}, {t, t*t}}; e1[t_] := Eigenvalues[M[t]]; e1[0] (* {0, 0} *) ... a degenerate matrix. N@Table[e1[i], {i, 1, 5}] // FullSimplify (* { {1.66005, 0.181422}, {3.70197, 1.20732}, {8.651, 0.490124}, {15.8425, -0.599291}, {25.0545, ...


0

Due to not having such a framework at hand, I used the following workaround, which allowed me to still shorten some computation time as compared to doing everything by hand. It boils down to having a set of conventions in place for how to write functions of arbitrarily many variables (or vectors or matrices of these). Here is a summary of the main ideas: ...


3

V = {{176}, {648}}; MatrixForm[Mod[V, 26]]


4

None of the above are particularly "efficient", if that's your goal. By way of example, mat = Module[{p1 = Range[0, 2 # - 2, 2], p2}, p2 = p1*2; p1[[1 ;; ;; 2]] = 0; p2[[2 ;; ;; 2]] = 0; LowerTriangularize@Transpose[PadRight[{p1}, #, {2 p1, p2}]]] &; mat[200];//Timing (* {0., Null} *) And that's on an old netbook. Compared to ...


4

Here is my version using SparseArray: mat2[n_]:=SparseArray[{{i_,j_}/;And[i>j,Mod[i+j,2]==1]:> If[j==1,2,4](i-1)},{n,n},0.]; MatrixForm@mat2[10]


8

Update: here Table is faster and more user-friendly then Array. mat[n_] := LowerTriangularize@Table[2 (1 + Boole[j > 1]) (i - 1) Mod[i + j, 2], {i, n}, {j, n}]; mat[10] // MatrixForm It is fast and the result is packed array mat[1000] // Developer`PackedArrayQ // AbsoluteTiming (* {0.142522, True} *)


1

I think this meets the spec: gKirkland[rows_, columns_] := Outer[ Function[{i, j}, If[i <= j, 0, If[Mod[i + j, 2] == 0, 0, 1] If[j == 1, 1/2, 1] (4 (i - 1)) ] ], Range[1, rows], Range[1, columns]] gKirkland[16,16] gives the matrix as shown. gKirkland[1000,1000] evaluates in 3 seconds.


1

Making some suggestions for you code... Do[matrixtransformer[2^(i - 1) - m] = N[1/2^i,20], {i, Floor[Log[2, size]]}]; Note that I've used N[] for the values. Since we are not interested in the exact values using N[] reduces time. And for the second part, you can use MatrixPower[] instead of iterating the multiplication. Its quiet fast. But the big ...


2

Suppose we have a grid like this: x = NestList[RotateRight, {1.5, 2/3, Pi, 9/7`, "!"}, 5]; Grid[x] It looks like this in the Front End: The image above was produced by selecting the Cell bracket and choosing File > Save Selection As.... If we use the Context Menu item Copy As > Plain Text we get: 1.5 2/3 \[Pi] 1.28571 ! ! 1.5 2/3 \[Pi] 1.28571 ...


2

Try this: Delete[L1, {#} & /@ L3] Delete[L2, {#} & /@ L3] (* {{2}, {5}, {0}, {7}, {8}} *) (* {2, 5, 0, 7, 8} *) Have fun!


1

There are several ways but the one I like is the following: If L1 and L2 have same length then: index = Complement[Range[Length[L1]], L3]; L1[[index]] (*{{2}, {5}, {0}, {7}, {8}}*) L2[[index]] (*{2, 5, 0, 7, 8}*)


1

It is the first time when I see nested Tuples. However, the output is quite simple: Tuples[Tuples[Tuples[{0,1},n],n],m] produces a list of all possible $m\times n\times n$ arrays with elements $0$ or $1$. To sum up a certain function h we can use the following function count[h_, d_] := Sum @@ Prepend[{#, 0, 1} & /@ Flatten@#, h@#] ...



Top 50 recent answers are included