i tried to construct a matrix from the coefficients of my solution, but problem that;
1; how can i get coefficients out of Solve
2; some Matrix elements are empty so i must assign 0 in those empty cells. and that's why it doesn't construct matrix directly by MatrixForm.
look at Code after Sol input**
Clear["Global`*"]
Needs["VariationalMethods`"]
n = 4;
m = 0.145;
Subscript[x, 0][t_] = 0;
"Those two initial condition make some cells empty that's why i can't directly construct a matrix using matrixform"
Subscript[x, n + 1][t_] = 0;
Subscript[k, (j_)?EvenQ] = 1.7;
Subscript[k, (j_)?OddQ] = 5;
Subscript[k, 0] = 1;
Subscript[k, n + 1] = 1;
ue[x_, t_, k_, n_] :=
(1/2)*Sum[Subscript[k, j]*(Subscript[x, j - 1][t] - Subscript[x, j][t])^2,
{j, 1, n + 1}];
te[x_, t_, n_] := (1/2)*m*Sum[Derivative[1][Subscript[x, j]][t]^2, {j, 1, n}];
lg[x_, t_, k_, n_] := te[x, t, n] - ue[x, t, k, n];
eq[x_, t_, k_, n_] := Expand[EulerEquations[lg[x, t, k, n],
Table[Subscript[x, j][t], {j, 1, n}], t]];
sol = Simplify[MatrixForm[Solve[eq[x, t, k, n], Table[Derivative[2][Subscript[x, j]][t],
{j, 1, n}]]]]
" I Tried these down with all ways never give me coefficients alone so i put them in a matrix i just need the number with no x[t] or x''[t]"
rules = CoefficientRules[lst[j], {Table[Derivative[2][Subscript[x, j]][t], {j, 1, n}]}]
matr = CoefficientArrays[lst, Table[Derivative[2][Subscript[x, j]][t], {j, 1, n}]]
lst = List @@ sol
Subscript
s isn't recommended. Secondly, you are trying to useCoefficientRules
andCoefficientArrays
onlst
before it's even defined. Furthermore, it seems likelst
is aList
, and yet insideCoefficientRules
, you are usinglst[j]
when likely it should belst[[j]]
. Unfortunately, Mathematica.SE is not a debugging service, so unless you can focus on a specific issue with Mathematica that you are having, it's difficult to help. Also, perhaps you should explain what you are trying to do. $\endgroup$MatrixForm
to define matrices, it is only a display wrapper and interferes with calculations. See mathematica.stackexchange.com/questions/3098/… $\endgroup$