# Solving a system of linear equations with a For-loop [closed]

I need to find the value of c1, c2, c3, c4 and c5, but the output from my code is the simplified equations, not the exact value of c1, c2, c3, c4 and c5. How can I get the values of c1, c2, c3, c4 and c5 without having to insert those into 'Solve'?

n = 5;
m = n + 1;
For[i = 1; t = c, i < m, i++,
t =
q Subscript[c, i - 1] - q Subscript[c, i] +
e (Subscript[c, i -1] Subscript[c, i]) +
e (Subscript[c, i + 1] - Subscript[c, i]) -
v Subscript[c, i] + Subscript[w, i] == 0;
Print[Solve[t]]];

• Do you want to solve all equations simultaneously or each separately? Also, for me, Solve returns the solution, but it solves for $w_i$ instead of $c_i$ - you can use the second argument of Solve to specify what it should solve for – Lukas Lang Oct 8 '19 at 8:22

A simplified version using indexed variables rather than subscripts.

The result will become more complicated and take significantly longer to evaluate as n increases.

Clear["Global*"]

Format[c[i_]] := Subscript[c, i]
Format[w[i_]] := Subscript[w, i]

n = 2;

(eqns = q c[# - 1] - q c[#] + e (c[# - 1]*c[#]) +
e (c[# + 1] - c[#]) - v c[#] + w[#] == 0 & /@
Range[n]) // Column


Solve[eqns, Array[c, n]] // Simplify
`