# Help in solve the matrix

I have written the following code. I have two main problems. The first is how to solve the matrix for different Omega, and the second is that if I put letters instead of numbers for k or m, the values will not add up(plus).

Subscript[k, 1] = K;
Subscript[k, 2] = K;
Subscript[k, 3] = K;
Subscript[m, 1] =M;
Subscript[m, 2] = 2*M;
Subscript[m, 3] = 2*M;
n = 3;
Format[m[n_]] := Subscript[m, n];
mv = Array[m, n];
(mm = (mv) IdentityMatrix[n]) // MatrixForm
Format[k[n_]] := Subscript[k, n];
kv = Array[k, n];
(kk = (kv + Join[Rest[kv], {0}]) IdentityMatrix[n] +
DiagonalMatrix[-Rest[kv], 1] +
DiagonalMatrix[-Rest[kv], -1]) // MatrixForm
(Omega = Solve[Det[kk - mm*\[Omega]] == 0, \[Omega]]) // N
(Time = 2 Pi/Sqrt[Omega] // RootReduce) // N
(mA = kk - mm*Omega[[i]] // RootReduce);
mC = {0, 0};
mX = Array[\[Phi], 2];
eqn = mA.mX == mC;
sol = Solve[eqn, mX]
(sol = (SolveAlways[eqn, mX])) // N


And how to get the answer in the form of a matrix as shown below

n = 3
Table[Subscript[\[CapitalPhi], i, j], {i, n}, {j, n}];
MatrixForm[%]


I thought maybe it would help, the top matrix is a modal matrix for structural modes

In the book it is mentioned that for each Omega there is a Phi vector which is known as the special vector or the characteristic vector, also elsewhere the unit value is considered for the component related to the first class.

Clear["Global*"]

k[1] = 4000;
k[2] = 4000;
k[3] = 5000;
m[1] = 10;
m[2] = 2;
m[3] = 5;
n = 3;

mv = m /@ Range[n];
mm = (mv) IdentityMatrix[n];
kv = k /@ Range[n];

(kk = (kv + Join[Rest[kv], {0}]) IdentityMatrix[n] +
DiagonalMatrix[-Rest[kv], 1] + DiagonalMatrix[-Rest[kv], -1]);

(Omega = ω /. Solve[Det[kk - mm*ω] == 0, ω]) // N

(* {177.181, 857.532, 5265.29} *)

(Time = 2 Pi/Sqrt[Omega] // RootReduce) // N

(* {0.472032, 0.214563, 0.0865902} *)

(mA = Table[kk - mm*Omega[[i]], {i, n}] // RootReduce);

mC = ConstantArray[0, n];

Format[ϕ[n_]] := Subscript[ϕ, n];

mX = Array[ϕ, n];

eqns = Table[mA[[i]].mX == mC, {i, n}];

(sol = Solve[#, mX] & /@ eqns // RootReduce // Quiet) /. x_Root :> N[x]


The solution gives ϕ[2] and ϕ[3] in terms of ϕ[1]. If instead you want ϕ[1] and ϕ[2] in terms of ϕ[3],

(sol2 = Solve[#, Most@mX, MaxExtraConditions -> All] & /@ eqns // RootReduce //
Quiet) /. x_Root :> N[x]


I do not understand the relation of the results to the pictures that you show.

EDIT: Using symbolic values

Clear["Global*"]

k[1] = K;
k[2] = K;
k[3] = K;
m[1] = M;
m[2] = 2*M;
m[3] = 2*M;
n = 3;

mv = Array[m, n];
(mm = (mv) IdentityMatrix[n]) // MatrixForm;

kv = Array[k, n];
(kk = (kv + Join[Rest[kv], {0}]) IdentityMatrix[n] +
DiagonalMatrix[-Rest[kv], 1] + DiagonalMatrix[-Rest[kv], -1]) //
MatrixForm;

(Omega = ω /. Solve[Det[kk - mm*ω] == 0, ω])

(* {K/M, (5 K - Sqrt[21] K)/(4 M), (5 K + Sqrt[21] K)/(4 M)} *)

Time = 2 Pi/Sqrt[Omega];

mA = Table[kk - mm*Omega[[i]], {i, n}];

mC = ConstantArray[0, n];

Format[ϕ[m_, n_]] := Subscript[ϕ, m, n]

mX = Array[ϕ, {n, n}];

eqn = Table[mA[[i]].mX[[i]] == mC, {i, n}];

sol = Table[Solve[eqn[[i]], mX[[i]]], {i, n}] // Quiet


• Your comment is unclear. First, do not set k[2] = k Since k is being used as an indexed variable; do not also try to use it as a separate variable. At best it is confusing. Second, what "answer" are you talking about? In any event, anywhere k[1] + k[2] occurs it would be K + k since K and k are distinct. As I said before, if you are having a problem with your code show the actual code that demonstrates the problem. – Bob Hanlon Dec 11 '20 at 15:46
• First of all, thank you very much for providing the solution, and then I have to say that I realized my mistake and for this reason I deleted the comment, I put lowercase(k) letters instead of uppercase(K),And now the problem is solved but... – Scott Constantine Dec 11 '20 at 19:22
• To solve the problem Phi must be like this {{\[Phi][1, 1], \[Phi][1, 2], \[Phi][1, 3]}, {\[Phi][2, 1], \[Phi][2, 2], \[Phi][2, 3]}, {\[Phi][3, 1], \[Phi][3, 2], \[Phi][3, 3]}} but in your code is {Subscript[\[Phi], 1], Subscript[\[Phi], 2]} – Scott Constantine Dec 11 '20 at 19:36
• The question in your comment makes no sense to me. The phi for a given omega have a set relationship. They cannot all be arbitrarily set. At most one of the three. To ask a question show what you have tried and state where you are having a problem. – Bob Hanlon Dec 13 '20 at 16:40
• sol /. {\[Phi][1, 1] -> 1, \[Phi][2, 1] -> 1, \[Phi][3, 1] -> 1} Note that as previously stated, only one of the phi for an omega can be assigned a value. – Bob Hanlon Dec 13 '20 at 18:00