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

7 ビュー (過去 30 日間)
Yokuna
Yokuna 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 件のコメント
MSM Farhan
MSM Farhan 2021 年 7 月 27 日
N1=976:1:10000;
Q1=976:1:10000;
N=reshape (N1, 95, 95);
Q=reshape (q1, 95, 95);
Z0=4
Z1=1
f0=9.0336
f1=-0.3275
D1=10
D2=10
d1=10
d2=10
H1=10
H2=10
n1=10
K1=10
c11=N*Z1-f1/4-(3/4)*cos(2*q)*(2*f0+ f1)-2*(sin(q).^2-cos(q).^2)*D1+4*(cos(q).^2)*
(cos (q).^2-3*(sin(q).^2))*d1+H1*sin(q)+H2*cos (q)-2*n1+4*K1*sin(2*q)
c22=N*Z1-f1/4-(3/4 )*cos(2*q)*(2*f0+f1)-2*(sin(q).^2-cos(q).^2)*D2+4*(cos(q).^2)*(cos
(q).^2-3*(sin(q).^2))*d2+H1*sin(q)+H2*cos (q)-2*n1+4*K1*sin(2*q)
c21=-N*Z1+f1/4-(3/4 )*cos(2*q)*f1+2*n1
a1=-(3/4 )*sin(2*q)*(f0+f1)+D1*sin(2*q)+2*d1*(cos(q).^2)*sin(2*q)-H1*cos(q)+H2*sin(q)- 2*K1*cos(2*q)
a2=-(3/4 )*sin(2*q)*(f0+ f1)+D2*sin(2*q)+2*d2*(cos(q).^2 )*sin(2*q)-H1*cos(q)+H2*sin(q)- 2*K1*cos(2*q)
C11=(c21+c22)/(2*(c11*c22-c21.^2))
C21=(c11+c21)/(2*(c21.^2-c11*c22))
e1=(a2-a1)*C11
e2=(a2-a1)*C21
E0=-N*Z0+f0/4-N*Z1-f1/4+(3/4)*cos(2*q)*(f0+f1)-(cos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)
h=surf (R);
h=xlabel (‘J/\omega‘);
h=ylabel (‘angle \theta (radians)‘);
h=Zlabel (‘E(\theta) /\omega‘);
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 月 17 日
syms x1 x2 x3 x_L t
eqns = [
x1 == t*(10*abs((18*x2)/125 - (24*x1)/125 + 111/50)^2*sign((18*x2)/125 - (24*x1)/125 + 111/50) + 10*abs((18*x2)/125 - (24*x1)/125 + 111/50)^(1/2)*sign((18*x2)/125 - (24*x1)/125 + 111/50)) - t*(10*abs((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100)^2*sign((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100) + 10*abs((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100)^(1/2)*sign((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100)) + 140
x2 == 2*t*(10*abs((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100)^2*sign((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100) + 10*abs((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100)^(1/2)*sign((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100)) - t*(10*abs((18*x2)/125 - (21*x3)/100 + 91/100)^2*sign((18*x2)/125 - (21*x3)/100 + 91/100) + 10*abs((18*x2)/125 - (21*x3)/100 + 91/100)^(1/2)*sign((18*x2)/125 - (21*x3)/100 + 91/100)) - t*(10*abs((18*x2)/125 - (24*x1)/125 + 111/50)^2*sign((18*x2)/125 - (24*x1)/125 + 111/50) + 10*abs((18*x2)/125 - (24*x1)/125 + 111/50)^(1/2)*sign((18*x2)/125 - (24*x1)/125 + 111/50)) + 140
x3 == t*(10*abs((18*x2)/125 - (21*x3)/100 + 91/100)^2*sign((18*x2)/125 - (21*x3)/100 + 91/100) + 10*abs((18*x2)/125 - (21*x3)/100 + 91/100)^(1/2)*sign((18*x2)/125 - (21*x3)/100 + 91/100)) - t*(10*abs((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100)^2*sign((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100) + 10*abs((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100)^(1/2)*sign((24*x1)/125 - (36*x2)/125 + (21*x3)/100 - 313/100)) + 140
x_L==0.002*x1*x1
x1+x2+x3==420+x_L]
eqns = 
E2 = lhs(eqns)-rhs(eqns)
E2 = 
F = matlabFunction(E2, 'vars', {[x1,x2,x3,x_L], t});
T = linspace(0,3,500);
nT = length(T);
sols = zeros(nT, 4);
x0 = [140, 140, 140, 140^2*0.002];
options = optimoptions(@fsolve, 'Algorithm', 'levenberg-marquardt', 'display', 'none');
have_warned = false;
have_warned2 = false;
for tidx = 1 : nT
[thissol, ~, exitflag, output] = fsolve(@(x) F(x,T(tidx)), x0, options);
sols(tidx, :) = thissol;
x0 = thissol;
if exitflag <= 0
if ~have_warned
warning('solution failure code %d starting at time = %g', exitflag, T(tidx));
have_warned = true;
disp(output)
end
elseif ~have_warned2
warning('Solutions resumed at time = %g', T(tidx));
have_warned2 = true;
end
end
Warning: solution failure code -2 starting at time = 0
iterations: 3 funcCount: 20 stepsize: 0.0071 cgiterations: [] firstorderopt: 2.1854e-04 algorithm: 'levenberg-marquardt' message: '↵No solution found.↵↵fsolve stopped because the last step was ineffective. However, the vector of function↵values is not near zero, as measured by the value of the function tolerance. ↵↵<stopping criteria details>↵↵fsolve stopped because the sum of squared function values, r, is changing by less ↵ than options.FunctionTolerance = 1.000000e-06 relative to its initial value.↵However, r = 3.670370e+02, exceeds sqrt(options.FunctionTolerance) = 1.000000e-03.↵↵'
plot(T, sols);
legend({'x1', 'x2', 'x3', 'x_L'});
Despite the graph, the messages tell you there was no solution.
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 件のコメント
Ildeberto de los Santos Ruiz
Ildeberto de los Santos Ruiz 2021 年 7 月 21 日
編集済み: Ildeberto de los Santos Ruiz 2021 年 7 月 21 日
Original post from @Shiv:
If someone could help me to plot x1 vs t from the information.
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.

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

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by