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

조회 수: 4 (최근 30일)
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?

채택된 답변

John D'Errico
John D'Errico 2023년 1월 27일
편집: John D'Errico 2023년 1월 27일
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.

추가 답변 (1개)

Torsten
Torsten 2023년 1월 27일
편집: Torsten 2023년 1월 27일
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
joshua payne
joshua payne 2023년 1월 27일
yes youre correct, but i was simply curious if i could do all the algebra in matlab and show it simplifies to 0

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by