Solving a system of equations with dependent variables symbolically

조회 수: 12 (최근 30일)
xav
xav 2023년 2월 26일
편집: xav 2023년 2월 27일
I have got 4 equations defined symbolically
y = a*b -c
z = d*a+b
x = c*a+b
s = c*b-a
The unknowns are {a, b, c ,d} and they are all real.
I have got difficulties to write the system of equations with implicit variables in matrix form.
What would be the best method to solve the set of equations above, please? I have thought about substitution, but it is challenging.
Does matlab have already programmed functions in MuPad to solve such a system, please?

채택된 답변

Askic V
Askic V 2023년 2월 26일
syms a b c d x z y s
sol = solve([y==a*b-c,z==d*a+b,x==c*a+b,s==c*b-a],[a,b,c,d],'Real',true)
Warning: Solutions are parameterized by the symbols: u. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
sol = struct with fields:
a: -(s^7 + 3*s^6*u*x - 4*s^6*u*z + 4*s^6*y*z + s^5*u^4 + s^5*u^3*y + 3*s^5*u^2*x^2 - 5*s^5*u^2*x*z + 2*s^5*u^2*z^2 + s^5*u^2 + 11*s^5*u*x*y*z - 15*s^5*u*y*z^2 + s^5*u*y - 4*s^5*x^2*z^2 + 3*s^5*x^2 + 7*s^5*x*z^3 - 5*s^5*x*z + 6*s^5*y^2*z^2 - 3*s^5*… b: (- s^5*u^3 - s^5*u^2*y + 3*s^5*u*x^2 - 11*s^5*u*x*z + 9*s^5*u*z^2 - s^5*u - s^5*y + 2*s^4*u^4*x - 3*s^4*u^4*z + s^4*u^3*x*y - 6*s^4*u^3*y*z + 5*s^4*u^2*x^3 - 19*s^4*u^2*x^2*z + 22*s^4*u^2*x*z^2 + 3*s^4*u^2*x - 4*s^4*u^2*y^2*z - 8*s^4*u^2*z^3 - … c: (s^6*u - s^5*u^2*x + s^5*u^2*z + 4*s^5*u*y*z - s^5*x + s^5*z + s^4*u^3*x^2 - 3*s^4*u^3*x*z + 2*s^4*u^3*z^2 - 4*s^4*u^2*x*y*z + 4*s^4*u^2*y*z^2 - s^4*u*x^4 + 10*s^4*u*x^3*z - 34*s^4*u*x^2*z^2 + 4*s^4*u*x^2 + 42*s^4*u*x*z^3 - 11*s^4*u*x*z + 6*s^4… d: u
sol.a, sol.b,sol.c, sol.d
ans = 
ans = 
ans = 
ans = 
u
  댓글 수: 11
Walter Roberson
Walter Roberson 2023년 2월 26일
syms a b c d e f g
syms x y z w u v s
syms cte1 cte2
eqns = [x == a *cte1 - e * c, y == - (b * e) / cte2, z == (a * g) / cte2, w == d * g - b * f, u == (a * e) / cte2, v == cte1 * b + e * d, s == a * f + c * g];
a_partial = solve(eqns(1), a)
a_partial = 
eqns2 = subs(eqns(2:end), a, a_partial);
b_partial = solve(eqns2(1), b)
b_partial = 
eqns3 = subs(eqns2(2:end), b, b_partial);
c_partial = solve(eqns3(end), c)
c_partial = 
eqns4 = subs(eqns3(1:end-1), c, c_partial);
d_partial = solve(eqns4(end), d)
d_partial = 
eqns5 = subs(eqns4(1:end-1), d, d_partial);
e_partial = solve(eqns5(end), e)
e_partial = 
eqns6 = subs(eqns5(1:end-1), e, e_partial); %now has two rows because two e solutions
f_partial_a_sol = solve(eqns6(1,1), f, 'returnconditions', true)
f_partial_a_sol = struct with fields:
f: [2×1 sym] parameters: [1×0 sym] conditions: [2×1 sym]
f_partial_a = f_partial_a_sol.f
f_partial_a = 
f_partial_a_sol.conditions
ans = 
f_partial_b_sol = solve(eqns6(2,1), f, 'returnconditions', true)
f_partial_b_sol = struct with fields:
f: [2×1 sym] parameters: [1×0 sym] conditions: [2×1 sym]
f_partial_b = f_partial_b_sol.f
f_partial_b = 
f_partial_b_sol.conditions
ans = 
eqns7_a = subs(eqns6(1,2:end), f, f_partial_a)
eqns7_a = 
eqns7_b = subs(eqns6(2,2:end), f, f_partial_b)
eqns7_b = 
g_partial_aa = solve(eqns7_a(1,1), g)
g_partial_aa = 
g_partial_ab = solve(eqns7_a(2,1), g)
g_partial_ab = 
g_partial_ba = solve(eqns7_b(1,1), g)
g_partial_ba = 
g_partial_bb = solve(eqns7_b(2,1), g)
g_partial_bb = 
You can now back-substitute the four different branches -- each f has two branches and each of those leads to two different g.
After you get all the way back to a, b, c, d, e, f, g coefficients, you might want to try to prove that all of the outputs are real-valued. That might be a bit tricky, especially without knowing the signs of x y z w u v s cte1 cet2 .
You could possibly cut several steps off of the process by solving eqns([1 2 end-2:end]) for [a b c d e] in one step and then go after f and g.
xav
xav 2023년 2월 27일
편집: xav 2023년 2월 27일
Many thanks Walter Roberson! That is a great deal helpful!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by