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

2 ビュー (過去 30 日間)
Shiv
Shiv 2021 年 6 月 22 日
コメント済み: Walter Roberson 2021 年 7 月 27 日
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;
%Equations
x1 =t*x1+x2+t*x3;
x2 = 2*t*x1+t*x2+x3;
x3 = t*x1+x2+x3;
% Equality constraint
x1+x2+x3=420;
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 7 月 27 日
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.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 6 月 23 日
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;
x1+x2+x3==420]
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 = 
vpa(ans,10)
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.
  20 件のコメント
Walter Roberson
Walter Roberson 2021 年 7 月 18 日
There does not appear to be any solution for that system of equations.

サインインしてコメントする。

その他の回答 (1 件)

ILDEBERTO DE LOS SANTOS RUIZ
ILDEBERTO DE LOS SANTOS RUIZ 2021 年 7 月 21 日
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)
ezplot(x1,[0,2])
  5 件のコメント
Walter Roberson
Walter Roberson 2021 年 7 月 21 日
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 = 
ezplot(x1_12,[-2,5])
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:
ezplot(x1_12,[2.5,3.5])
hold on
ezplot(x1_13,[2.5,3.5])
ezplot(x1_23,[2.5,3.5])
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.

サインインしてコメントする。

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by