I want to check if something algebraically simplifies to 0 when i sub in values

3 views (last 30 days)
clc
clear
syms q1 q2 q3 g Y u a rho e
E=[q2,((q2^2)/q1)*(1-(g-1)*.5)+(g-1)*q3,((q3*q2)/q1)+(g-1)*((q3*q2)/q1)-.5*(g-1)*(q2^3/q1^2)]
Q=[q1,q2,q3]
J=jacobian(E,Q)
pretty((2*q2^3*(g/2 - 1/2))/q1^3 - (q2*q3)/q1^2 - (q2*q3*(g - 1))/q1^2)
pretty(q3/q1 - (3*q2^2*(g/2 - 1/2))/q1^2 + (q3*(g - 1))/q1)
pretty(q2/q1 + (q2*(g - 1))/q1)
C=det(J-Y*eye(3))
C2=simplify(C)
so i have Y= u, u-a and u+a
q1= rho, q2=rho*u, and q3=e
all of these are symbolic and have no values but i want to sub in all the q's and 1 by 1 the Y's to see if they simplify to 0.
how would i do this?

Accepted Answer

John D'Errico
John D'Errico on 27 Jan 2023
Edited: John D'Errico on 27 Jan 2023
syms q1 q2 q3 g Y u a rho e
E=[q2,((q2^2)/q1)*(1-(g-1)*.5)+(g-1)*q3,((q3*q2)/q1)+(g-1)*((q3*q2)/q1)-.5*(g-1)*(q2^3/q1^2)];
Q=[q1,q2,q3];
J=jacobian(E,Q);
pretty((2*q2^3*(g/2 - 1/2))/q1^3 - (q2*q3)/q1^2 - (q2*q3*(g - 1))/q1^2)
3 / g 1 \ q2 | - - - | 2 \ 2 2 / q2 q3 q2 q3 (g - 1) --------------- - ----- - ------------- 3 2 2 q1 q1 q1
pretty(q3/q1 - (3*q2^2*(g/2 - 1/2))/q1^2 + (q3*(g - 1))/q1)
2 / g 1 \ q2 | - - - | 3 q3 \ 2 2 / q3 (g - 1) -- - --------------- + ---------- q1 2 q1 q1
pretty(q2/q1 + (q2*(g - 1))/q1)
q2 q2 (g - 1) -- + ---------- q1 q1
C=det(J-Y*eye(3))
C = 
C2=simplify(C)
C2 = 
Now, if you have q1,q2,q3
C2 = subs(C2,[q1,q2,q3],[rho,rho*u,e])
C2 = 
expand(C2)
ans = 
So nothing special happening so far. Now you want t osub in those possible values for Y. Just do it.
simplify(expand(subs(C2,Y,[u,u+a,u-a])))
ans = 
Simple enough. When Y == u, everything goes away, but not so in the other cases.
Another way of doing this is to see for which values of Y, C2 would be zero.
Ysol = solve(C2 == 0,Y)
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
Ysol = 
It finds three solutions, one of which is the case you wanted. The other two are alternatives. I could check under which conditions they apply, but most likely it would just tell me that rho cannot be zero.

More Answers (1)

Torsten
Torsten on 27 Jan 2023
Edited: Torsten on 27 Jan 2023
Euler equations of gas dynamics ?
Eigenvalues and Eigenvectors of the Jacobian are well-studied. Why reinvent the wheel ?
syms q1 q2 q3 g Y u a rho e
E=[q2,((q2^2)/q1)*(1-(g-1)*.5)+(g-1)*q3,((q3*q2)/q1)+(g-1)*((q3*q2)/q1)-.5*(g-1)*(q2^3/q1^2)];
Q=[q1,q2,q3];
J=jacobian(E,Q);
[S,V] = eig(J)
S = 
V = 
S = simplify(subs(S,[q1 q2 q3],[rho rho*u e]))
S = 
V = simplify(subs(V,[q1 q2 q3],[rho rho*u e]))
V = 
  1 Comment
joshua payne
joshua payne on 27 Jan 2023
yes youre correct, but i was simply curious if i could do all the algebra in matlab and show it simplifies to 0

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!