2
$\begingroup$

I was trying to solve this system of equations:

totalParts=4;
Solve[
 Join[
  {n[0] == 0, n[totalParts - 1] == 1},
  Table[2 n[i]^2 == n[i + 1]^2 - n[i - 1]^2, {i, 1, totalParts - 2}]
 ],
 Table[n[i], {i, 1, totalParts - 2}]]

Solve gave me {} as answer. I started to wonder where I've made a mistake, but guessed that Reduce may give an answer. Interestingly, the mere replacement of Solve with Reduce in the above code gives me

n[3] == 1 && 
 n[0] == 0 && (n[1] == -(1/Sqrt[5]) || 
   n[1] == 1/Sqrt[5]) && (n[2] == -Sqrt[(2/5)] || n[2] == Sqrt[2/5])

I.e. the system does have a solution, and I've checked by substitution that the solution is right.

Why didn't Solve give it or at least complained that it can't be solved with methods available to Solve as it sometimes does? I'd expect something like

{{n[1]->-(1/Sqrt[5]),n[2]->-Sqrt[(2/5)]},
{n[1]->-(1/Sqrt[5]),n[2]->Sqrt[(2/5)]},
{n[1]->(1/Sqrt[5]),n[2]->-Sqrt[(2/5)]},
{n[1]->(1/Sqrt[5]),n[2]->Sqrt[(2/5)]}}
$\endgroup$
  • $\begingroup$ In Solve you have less variables than equations. Go with {i, 0, totalParts - 1} to obtain the solutions. $\endgroup$ – corey979 Sep 24 '16 at 8:40
  • $\begingroup$ Or use MaxExtraConditions -> Automatic to allow conditions on the other parameters $\endgroup$ – Simon Woods Sep 24 '16 at 8:41
  • $\begingroup$ @corey979, @ SimonWoods these hints could go into answers. $\endgroup$ – Ruslan Sep 24 '16 at 8:43
3
$\begingroup$

Solve wants the same number of equations and variables, so

totalParts = 4;
Solve[Join[{n[0] == 0, n[totalParts - 1] == 1}, 
  Table[2 n[i]^2 == n[i + 1]^2 - n[i - 1]^2, {i, 1, totalParts - 2}]],
  Table[n[i], {i, 0, totalParts - 1}]]

enter image description here

But it's a wasted effort to solve an equation of the type n[0] == 0 and n[3] == 1, so

{n[0] = 0, n[totalParts - 1] = 1};
Solve[Table[
  2 n[i]^2 == n[i + 1]^2 - n[i - 1]^2, {i, 1, totalParts - 2}], 
 Table[n[i], {i, 1, totalParts - 2}]]

enter image description here


Let me also incorporate and elaborate on the comment of Simon Woods about MaxExtraConditions.

sol = Solve[
  Join[{n[0] == 0, n[totalParts - 1] == 1}, 
   Table[2 n[i]^2 == n[i + 1]^2 - n[i - 1]^2, {i, 1, 
     totalParts - 2}]], Table[n[i], {i, 1, totalParts - 2}], 
  MaxExtraConditions -> Automatic]

returns a conditional expression

enter image description here

which isn't very transparent, but one can display the solution with the assumption that the conditions are met with

Normal @ sol

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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