i have this code it return EigenValues, it's all right.
Problem:
i have to specify n
in order for summation and solution to give output.
Solution:
i just need to put them in Block or Module to calculate EigenValues of system n without specifying prior n
so i can later just plug any n
for the system.
This is my Code
Clear["Global`*"]
Needs["VariationalMethods`"]
n = 4; (* thats what i mean problem and solution*)
m = 0.145;
Subscript[x, 0][t_] = 0;
Subscript[x, n + 1][t_] = 0;
Subscript[k, (j_)?EvenQ] = 1.7;
Subscript[k, (j_)?OddQ] = 5;
Subscript[k, 1] = 0;
Subscript[k, n + 1] = 0;
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]];
sol1[x_, t_, k_, n_] := Simplify[Solve[eq[x, t, k, n],
Table[Derivative[2][Subscript[x, j]][t], {j, 1, n}]]];
lst = -(m*D[Table[Derivative[2][Subscript[x, j]][t], {j, 1, n}] /.
First[sol1[x, t, k, n]], {Table[Subscript[x, j][t], {j, 1, n}]}]);
Eigenvalues[lst]
The Solution is to put them in Block
defined by n
Example given but doesn't return any values for me!
Clear["Global`*"]
Needs["VariationalMethods`"]
w[n_] := Block[{p = n},
m = 0.145;
Subscript[x, 0][t_] = 0;
Subscript[x, p + 1][t_] = 0;
Subscript[k, (j_)?EvenQ] = 1.7;
Subscript[k, (j_)?OddQ] = 5;
Subscript[k, 1] = 0;
Subscript[k, p + 1] = 0;
ue[x_, t_, k_, p_] := (1/2)*Sum[Subscript[k, j]*
(Subscript[x, j - 1][t] - Subscript[x, j][t])^2, {j, 1, p + 1}];
te[x_, t_, p_] := (1/2)*m*Sum[Derivative[1][Subscript[x, j]][t]^2, {j, 1, p}];
lg[x_, t_, k_, p_] := te[x, t, p] - ue[x, t, k, p];
eq[x_, t_, k_, p_] := Expand[EulerEquations[lg[x, t, k, p],
Table[Subscript[x, j][t], {j, 1, p}], t]];
sol1[x_, t_, k_, p_] :=
Simplify[Solve[eq[x, t, k, p], Table[Derivative[2][Subscript[x, j]][t],
{j, 1, p}]]];
lst = -(m*D[Table[Derivative[2][Subscript[x, j]][t], {j, 1, p}] /.
First[sol1[x, t, k, p]], {Table[Subscript[x, j][t], {j, 1, p}]}]);
Eigenvalues[lst]
]
so When i put
w[4]
it gives eigenvalues for system with n=1
so i choose independently my n
Then i could ListPlot All 1
i could do this by
q=Table[i,{i,1,30}]
ListPlot[w[q]]
Block
toModule
and fixing the typo "EvepQ". I'm also nor sure you want theDrop
at the end - it removes all the values from the list. $\endgroup$