Solving a system of equations with dependent variables symbolically

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?

 Accepted Answer

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 Comments

Many thanks for your answer !
If I wanted to use matlinsolve(A, b), what would A and b be of the system of equations above, please?
You need to have a system of linear equations.
Your system is clearly nonlinear.
Thank you for your reply.
Could solve in Matlab, solve the set of equations below, please:
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
w = (b * g) / cte2
where {a , b, c, d, e, f, g} are unknowns.
cte1 and cte2 are constant.
You have more equations than unknowns. Most probably, you won't get a solution.
There are 7 equations and 7 unknowns, w is expressed differently twice, I could use its second expression for verification.
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
where {a , b, c, d, e, f, g} are unknowns.
cte1 and cte2 are constant.
And setting up the problem as @Askic V did does not give you a solution ? Or don't you have the symbolic toolbox licenced ? Or are you to lazy to imitate his code ?
My school has a licence but booking hours is limited, thus I am anticipating some questions that I might have during my time limited session. I have used the function fsolve to solve the set of 7 equations, it took time to process then just rewrited the command whithout the answers.
If you format your code here with the "CODE" button and use the right green arrow in the above menue, you can test such small codes like yours here in the forum with the recent MATLAB release.
Many thanks! very good to know! it does not seem to converge to a solution.
Is there better function than solve?
syms a b c d e f g
syms x y z w u v s
syms cte1 cte2
[a b c d e f g] = solve([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,b,c,d,e,f,g],'Real',true)
a = Empty sym: 0-by-1 b = Empty sym: 0-by-1 c = Empty sym: 0-by-1 d = Empty sym: 0-by-1 e = Empty sym: 0-by-1 f = Empty sym: 0-by-1 g = Empty sym: 0-by-1
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.
Many thanks Walter Roberson! That is a great deal helpful!

Sign in to comment.

More Answers (0)

Products

Release

R2022b

Asked:

xav
on 26 Feb 2023

Edited:

xav
on 27 Feb 2023

Community Treasure Hunt

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

Start Hunting!