0
$\begingroup$

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]]];
$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – Lukas Lang Oct 8 '19 at 8:22
3
$\begingroup$

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

enter image description here

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

enter image description here

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.