MATLAB Answers

How to solve 3 simultaneous algebraic equations with a equality constraint.

7 views (last 30 days)
Shiv on 22 Jun 2021
Commented: Walter Roberson on 27 Jul 2021
If someone could help me to plot x1 vs t from the information. Please if someone could give any idea.
%Initial conditions
x1=140; x2=140; x3=140;
x1 =t*x1+x2+t*x3;
x2 = 2*t*x1+t*x2+x3;
x3 = t*x1+x2+x3;
% Equality constraint
Walter Roberson
Walter Roberson on 27 Jul 2021
That does not appear to be related? please open a new question, and when you do please be more clear what you are asking for.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 23 Jun 2021
You cannot usefully plot x1 vs t. Your system defines three specific sets of points, two of which are complex-valued
syms x1 x2 x3 t
eqn = [x1 == t*x1+x2+t*x3;
x2 == 2*t*x1+t*x2+x3;
x3 == t*x1+x2+x3;
eqn = 
sol = solve(eqn,[x1, x2, x3, t], 'maxdegree', 3)
sol = struct with fields:
x1: [3×1 sym] x2: [3×1 sym] x3: [3×1 sym] t: [3×1 sym]
[sol.x1, sol.x2, sol.x3, sol.t]
ans = 
ans = 
so the only real-valued solution is x1 about -235, x2 about 732, x3 about -76, and t about 3.1 .
You might perhaps be expecting all-positive results, but look at your equations:
x3 = t*x1+x2+x3;
x3 appears with coefficient 1 on both sides, so you can subtract it from both sides, leading to
0 == t*x1 + x2
and if t and x1 and x2 are all positive, then that equation cannot be satisfied. It can potentially be satisfied if t and x2 are both 0
If you substitute t = 0 into your first three equations, you can come out with a consistent solution only if x1 = x2 = x3 = 0. However, that does not satisfied the constraint. This establishes that there is no consistent solution for arbitrary times.

Sign in to comment.

More Answers (1)

You only need to express in terms of t and plot that relationship:
syms x1 x2 x3 t
x3 = solve(x1+x2+x3 == 420,x3)
EQ1 = x1 == t*x1+x2+t*x3;
EQ2 = x2 == 2*t*x1+t*x2+x3;
[x1,x2] = solve(EQ1,EQ2)
Walter Roberson
Walter Roberson on 21 Jul 2021
And the information given includes three equations plus one constraint equation.
syms x1 x2 x3 t
x3 = solve(x1+x2+x3 == 420,x3)
x3 = 
EQ1 = x1 == t*x1+x2+t*x3;
EQ2 = x2 == 2*t*x1+t*x2+x3;
EQ3 = x3 == t*x1+x2+x3;
[x1_12,x2_12] = solve(EQ1,EQ2)
x1_12 = 
x2_12 = 
[x1_13,x2_13] = solve(EQ1,EQ3)
x1_13 = 
x2_13 = 
[x1_23,x2_23] = solve(EQ2,EQ3)
x1_23 = 
x2_23 = 
hold on
ezplot(x1_13,[-2 5])
ezplot(x1_23,[-2 5])
hold off
legend({'EQ1,EQ2', 'EQ1,EQ3', 'EQ2,EQ3'}, 'location', 'southwest');
Three very different pairwise answers. It looks like there might be a common answer near t = 3; let us see:
hold on
hold off
legend({'EQ1,EQ2', 'EQ1,EQ3', 'EQ2,EQ3'}, 'location', 'southwest');
tsol = vpasolve(x1_12 == x1_13, 3)
tsol = 
X1 = subs([x1_12, x1_13, x1_23], t, tsol(2))
X1 = 
X2 = subs([x2_12, x2_13, x2_23], t, tsol(2))
X2 = 
So far, so good, the pairs of equation seem to check out.
X3 = subs(x3, [x1, x2], [X1(1), X2(1)])
X3 = 
That is, there is only one real-valued solution to all of the equations simultaneously.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!