0
$\begingroup$

My goal is to solve equation with subscripts. But the result shows {{}}. Strange enough, If I don't use subscripts, result shows. Is there a limitation in using subscripts? How to fix code below?

This code doesn't work. How to fix to use subscript?

 Clear["Global`*"]
 Solve[Subscript[y, 1] == Subscript[x, 1] + Subscript[x, 2] && 
  Subscript[y, 2] == Subscript[x, 1]/(
   Subscript[x, 1] + Subscript[x, 2]), {Subscript[x, 1], Subscript[x, 
  2]}]

This code works with no subscript.

Clear["Global`*"]
Solve[y1 == x1 + x2 && y2 == x1/(x1 + x2), {x1, x2}]
$\endgroup$
4
  • 4
    $\begingroup$ Don't use subscripts. Subscripts are primarily a formatting command. Use arrays a[[1]], a[[2]].. or functions a[1], a[2], instead $\endgroup$
    – bill s
    Apr 29 at 15:13
  • 1
    $\begingroup$ If you really need the output to have subscripts, you can use what @bills recommends and then convert to subscripts at the end: sol = Solve[y[1] == x[1] + x[2] && y[2] == x[1]/(x[1] + x[2]), {x[1], x[2]}]; sol /. x[i_] -> Subscript[x, i] /. y[i_] -> Subscript[y, i]. $\endgroup$
    – JimB
    Apr 29 at 15:55
  • 1
    $\begingroup$ MMA version 12.1 Both calculations work for me. $\endgroup$ Apr 29 at 15:58
  • 1
    $\begingroup$ You can format the display of indexed variables with subscripts, e.g., Clear["Global`*"]; Format[x[n_]] := Subscript[x, n]; Format[y[n_]] := Subscript[y, n]; Solve[y[1] == x[1] + x[2] && y[2] == x[1]/(x[1] + x[2]), {x[1], x[2]}] $\endgroup$
    – Bob Hanlon
    Apr 29 at 17:38
0
$\begingroup$

The output of your code would print as a list of associations showing the solution for x_1 and x_2. In regards to the {{}} present in the solution, this is the output of Solve[] when the there are multiple solutions.

https://reference.wolfram.com/language/ref/Solve.html

If you want to shorten what you typed, you can use the keyboard shortcut ctrl+- to type the subscript in line.

$\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.