solve a system of equations symbolically

3 views (last 30 days)
I want to solve a system of equations symbolically. But I faced some problems. I was wondering if you could guide me on why MATLAB is incapable of the determination of the Z as a function of a1 and a2? And how can I find Z?
Thanks for your attention in advance.
Here is my code:
syms a3 a2 a1
S= solve(eqn);
X = 
Y = 
Unrecognized field name "a3".

Accepted Answer

Paul on 20 Oct 2021
It looks like there are two equations with three unknowns for which there are many solutions. So solve() gives the results for two of the variables in terms of the third, which you can set to an arbitray value. In this case, it chose to solve for a1 and a2 in terms of a3. But you can make it solve for any two in terms of the third, for example a2 and a3 in terms of a1
syms a3 a2 a1
eqn = [a3-3*a2+10*a1==68,5*a3+6*a2+2*a1==31];
S = solve(eqn,[a2 a3])
S = struct with fields:
a2: (16*a1)/7 - 103/7 a3: 167/7 - (22*a1)/7
Now pick an arbitrary value for a1, say sqrt(3), and show that the solution satisfies the eqn
subs(eqn,[a1 a2 a3],[sqrt(3) subs([S.a2 S.a3],a1,sqrt(3))])
ans = 

Sign in to comment.

More Answers (0)


Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!