Matris ifadesini birden çok satıra bölme
Bir matris ifadesi verildiğinde
testm = {a + b, c + d, e};
{# , testm[[ # ]] // Simplify} & /@ Range[ Length[testm] ] // MatrixForm
\ begin {denklem} \ begin {pmatrix} 1 & a + b \\ 2 & c + d \\ 3 & e \\\ end {pmatrix} \ end {equation} Bunu \ begin {equation} olarak yeniden yazmak istiyorum \ begin {pmatrix} 1.1 & a \\ 1.2 & b \\ 2.1 & c \\ 2.2 & d \\ 3 & e \\\ end {pmatrix} \ end {equation}
Bunu nasıl yaparım? Sonunda, bunu \ begin {equation} (a + b) = A exp [I (k + l) m (n + o + p \ q)] Cos (r \ q) sahip olduğum daha karmaşık bir duruma genişletmek istiyorum s) + A exp (I (k + l) m (n + o + p \ q)) Sin (t \ u) \ end {denklem} 1.1'in yanındaki kosinüs terimini ve 1.2'nin yanındaki sinüs terimini görüntüler.
Yanıtlar
List @@@ {a + b, c + d}
testm = {Cos[a] + Sin[a], 5 + Sin[a]};
List @@@ testm
İstediğiniz aşağıdaki mi?
testm = {Cos[a] + Sin[a], 5 + Sin[a]};
m = List @@@ testm
Flatten[Table[{i.j, m[[i, j]]}, {i, 2}, {j, 2}], 1]
Güncellenmiş
Belki MapIndexed
çalışmalı
Clear["Global`*"];
testm = {a + b, c + d, e};
mat = List @@@ testm
Flatten[MapIndexed[f @@ {Dot @@ #2, #1} &, mat, {-1}]] /.
f -> List // MatrixForm
testm = {a + b, c + d, e};
index = StringTemplate[If[Length[#] == 2, "``.``", "``"]] @@ # &;
{index @ Position[testm, #, {-1}][[1]], #} & /@ Cases[testm, _Symbol, -1] // MatrixForm
Güncelleme
testm = {A Exp[I (k + l) m (n + o + p q)] Cos[r s] + A Exp[I (k + l) m (n + o + p q)] Sin[t u], c + d, e};
{index @ Position[testm, #, 2][[1]], #} & /@ Cases[testm, (_Symbol | _Times), 2] // MatrixForm
ClearAll[indexedMonomials]
indexedMonomials = Join @@
(MapIndexed[{Dot @@ #2, #} &, MonomialList@#, {2}] /. {{a_, b_}} :> {{First@a, b}}) &;
Misal:
testm2 = {A E^(I (k + l) m (n + o + p q)) Cos[r s] +
A E^(I (k + l) m (n + o + p q)) Sin[t u], a + b + x, c + d, e};
MapIndexed[{#2[[1]], #} &, testm2] // MatrixForm // TeXForm
$\left( \begin{array}{cc} 1 & A \cos (r s) e^{i m (k+l) (n+o+p q)}+A \sin (t u) e^{i m (k+l) (n+o+p q)} \\ 2 & a+b+x \\ 3 & c+d \\ 4 & e \\ \end{array} \right)$
indexedMonomials @ testm2 // MatrixForm // TeXForm
$\left( \begin{array}{cc} 1.1 & A \cos (r s) e^{i m (k+l) (n+o+p q)} \\ 1.2 & A \sin (t u) e^{i m (k+l) (n+o+p q)} \\ 2.1 & a \\ 2.2 & b \\ 2.3 & x \\ 3.1 & c \\ 3.2 & d \\ 4 & e \\ \end{array} \right)$