Im working on a loooooooooooooong formula. I want to replace (substitute?) certain combination of variables for another simpeler combination of variables (like for example F=m*a), anywhere in the formula where this combination exists.
I have a formula let say
sage: eq1=m*a==(b+c)*k
sage: eq2=d==a*m+f
sage: eq3=eq2.subs(eq1)/g
(doesnt work with the multiplication? just gives me the same answer as i had without the substitution)
so it does some kind of operation on equation 2 but I want to replace the a in equation 2 for equation 1
my code:
sage: A1, A2, A3, P1, P3, u1, u2, u3, r1, r2, r3 = var('A1 A2 A3 P1 P3 u1 u2 u3 r1 r2 r3')
sage: eq7a = P1 - P3 == -(A1*r1*u1^2 + A2*r2*u2^2 - A3*r3*u3^2)/A3
sage: eq7a.subs_expr(A3*r3*u3^2 == (A2*u2*r2 + A1*r1*u1)*u3)
sage: P1 - P3 == -(A1*r1*u1^2 + A2*r2*u2^2 - A3*r3*u3^2)/A3
The last one i want to turn the a3r3u3 into the longer one, but it just gives me back a3r3u3
-----------------------------------------------------------------------------------------------------------------solved up to here
also it does not work with the next one either and there is no minus in this?
sage: A1, A2, A3, P1, P2, P3, u1, u2, u3, r1, r2, r3, g, C, M1, M2, M3 = var('A1 A2 A3 P1 P2 P3 u1 u2 u3 r1 r2 r3 g C M1 M2 M3')
C')
sage: eq1=A3*(P1-P3)==A3*r3*u3^2-(A2*r2*u2^2+A1*r1*u1^2)
sage: eq2=A3*u3*r3==A2*u2*r2+A1*r1*u1
sage: eq3=(u3^2/2+g/(g-1)*P3/r3)*r3*u3*A3==(u2^2/2+g/(g-1)*P2/r2)*r2*u2*A2+(u1^2/2+g/(g-1)*P1/r1)*r1*u1*A1
sage: eq4=C==g/(g-1)*P3/r3+u3^2/2
sage: eq5a=solve([eq2],r3)
sage: eq5b=u3^2+2*g/(g-1)*(P3/(eq5a[0].rhs()))-2*C==0
eq5b=u3^2+2*g/(g-1)*(P3/(eq5a[0].rhs()))-2*C
sage: eq6=solve([eq5b],u3)
sage: eq7a=eq1/A3
sage: eq7b=eq7a.subs(-A3*r3*u3^2 eq7b=eq7a.subs_expr(A3*r3*u3^2==(A2*u2*r2+A1*r1*u1)*u3)
sage: eq7b
P1 - P3 == -(A2*u2*r2+A1*r1*u1)*u3)
sage: eq7c=eq7b.subs(u3==eq6[0].rhs())#only 1 root?
sage: eq7=solve([eq7c],P3)
sage: eq8a=eq7[0].rhs()/P1
sage: eq8b=eq8a.subs(A1*r1*u1^2/P1==g*A1*M1^2)
sage: eq8b (A1*r1*u1^2 -(A1*r1*u1^2 + A2*r2*u2^2 + A3*P1 - (A1*r1*u1^2 + A2*r2*u2^2 + A3*P1)*g - sqrt(A3^2*P3^2*g^2 + 2*((g^2 - 2*g + 1)*A1^2*r1^2*u1^2 + 2*(g^2 - 2*g + 1)*A1*A2*r1*r2*u1*u2 + (g^2 - 2*g + 1)*A2^2*r2^2*u2^2)*C))/(A3*P1)
sage: eq8a (A1*r1*u1^2 + A2*r2*u2^2 + A3*P1 - (A1*r1*u1^2 + A2*r2*u2^2 + A3*P1)*g - sqrt(A3^2*P3^2*g^2 + 2*((g^2 - 2*g + 1)*A1^2*r1^2*u1^2 + 2*(g^2 - 2*g + 1)*A1*A2*r1*r2*u1*u2 + (g^2 - 2*g + 1)*A2^2*r2^2*u2^2)*C))/(A3*P1)
A3*r3*u3^2)/A3
And the p3 isnt isolated eitherThe last one i want to turn the a3r3u3 into the longer one, but it just gives me back a3r3u3