4
$\begingroup$

I tried integrating two equation with the same structure, the first equation fails to evaluate completely - the answer is still in terms of integration. The second integration evaluated fine. The only difference between these two equation is that the first equation uses subscripts in the variable names. Does that mean Mathematica doesn't handle subscripted variables well?

The first equation:

Integrate[(Subscript[c, 1] Subscript[x, 1] + 
Subscript[c, 2] Subscript[x, 2]) Sqrt[(Subscript[c, 1] Subscript[y, 1] + 
Subscript[c, 2] Subscript[y, 2]) (Subscript[c, 1] Subscript[z, 1] + 
Subscript[c, 2] Subscript[z, 2])], Subscript[c, 1], Subscript[c, 2]]

The second equation:

Integrate[(c1 x1 + c2 x2) Sqrt[(c1 y1 + c2 y2) (c1 z1 + c2 z2)], c1, c2]
$\endgroup$
  • $\begingroup$ I believe it is generally recommended to avoid linear syntax in your coding. On a large scale it can theoretically slow things down, and on a smaller scale you can occasionally run into trouble in other places. I don't have any examples ready, but again it's recommended. $\endgroup$ – user6014 Oct 6 '16 at 3:05
  • $\begingroup$ Looks like a bug to me. $\endgroup$ – wolfies Dec 12 '16 at 14:47
  • $\begingroup$ As per the other comment its going to land you in a world of hurt trying to perfectly match notation in Mathematica. You are better off using text group above the code that executes to explain your code within which you can have something neat, formatted or merely pasted as an image from another application. $\endgroup$ – Ramble Dec 12 '16 at 17:29
  • 1
    $\begingroup$ Symbolize from the Notations package is often maligned around here but IMO is useful in many cases such as this $\endgroup$ – Mike Honeychurch Dec 12 '16 at 23:57
  • 1
    $\begingroup$ Note that this issue has nothing to to with subscripts -- it also fails to integrate over both variables if you use regular old downvalues: Integrate[(c[1] x[1] + c[2] x[2]) Sqrt[(c[1] y[1] + c[2] y[2]) (c[1] z[1] + c[2] z[2])], c[1], c[2]]. Definitely a problem with Integrate. People always want to pick on poor old subscripts! $\endgroup$ – Simon Rochester Dec 13 '16 at 6:11
7
$\begingroup$

Subscripts are generally more trouble than they are worth and cannot be used as variables. You can use Format to display variables as if subscripted.

Format[c1] := Subscript["c", 1] 
(* string used to avoid problem if symbol c has assigned value *)
Format[c2] := Subscript["c", 2]
Format[x1] := Subscript["x", 1]
Format[x2] := Subscript["x", 2]
Format[y1] := Subscript["y", 1]
Format[y2] := Subscript["y", 2]
Format[z1] := Subscript["z", 1]
Format[z2] := Subscript["z", 2]

expr = (c1 x1 + c2 x2) Sqrt[(c1 y1 + c2 y2) (c1 z1 + c2 z2)]

enter image description here

int=Integrate[expr, c1, c2]

enter image description here

The InputForm does not have the subscripts

int // InputForm

(Sqrt[(c1*y1 + c2*y2)*(c1*z1 + c2*z2)]*
  ((-3*c1^4*(y2*z1 - y1*z2)^2*(x2*y2*z1 + 
      x2*y1*z2 - 2*x1*y2*z2))/
    (Sqrt[c1*y1 + c2*y2]*Sqrt[c1*z1 + c2*z2]) - 
   (8*Sqrt[y2]*Sqrt[z2]*(-2*c1*c2^2*y1*y2^2*z1*
       z2^2*(10*x2*y1*z1 + x1*y2*z1 + 
        x1*y1*z2) - 2*c1^2*c2*y1^2*y2*z1^2*z2*
       (x2*y2*z1 + x2*y1*z2 + 10*x1*y2*z2) + 
      c2^3*y2^2*z2^2*(-6*x2*y1*z1*
         (y2*z1 + y1*z2) + x1*(3*y2^2*z1^2 - 
          2*y1*y2*z1*z2 + 3*y1^2*z2^2)) + 
      c1^3*y1^2*z1^2*(-6*x1*y2*z2*
         (y2*z1 + y1*z2) + x2*(3*y2^2*z1^2 - 
          2*y1*y2*z1*z2 + 3*y1^2*z2^2))))/
    (y1^2*z1^2) + (12*c2^4*y2^(5/2)*z2^(5/2)*
     (y2*z1 - y1*z2)^2*(-2*x2*y1*z1 + 
      x1*y2*z1 + x1*y1*z2)*
     Log[2*c1*y1*z1 + c2*y2*z1 + c2*y1*z2 + 
       2*Sqrt[y1]*Sqrt[c1*y1 + c2*y2]*Sqrt[z1]*
        Sqrt[c1*z1 + c2*z2]])/
    (y1^(5/2)*Sqrt[c1*y1 + c2*y2]*z1^(5/2)*
     Sqrt[c1*z1 + c2*z2]) + 
   (12*c1^4*(y2*z1 - y1*z2)^2*(x2*y2*z1 + 
      x2*y1*z2 - 2*x1*y2*z2)*
     Log[c1*y2*z1 + c1*y1*z2 + 2*c2*y2*z2 + 
       2*Sqrt[y2]*Sqrt[c1*y1 + c2*y2]*Sqrt[z2]*
        Sqrt[c1*z1 + c2*z2]])/
    (Sqrt[c1*y1 + c2*y2]*Sqrt[c1*z1 + c2*z2])))/
 (768*y2^(5/2)*z2^(5/2))
$\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.