How to solve 3 simultaneous algebraic equations with a equality constraint.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yokuna
am 22 Jun. 2021
Kommentiert: Walter Roberson
am 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;
%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 Kommentare
MSM Farhan
am 27 Jul. 2021
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)-(c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1)
h=surf (R);
h=xlabel (‘J/\omega‘);
h=ylabel (‘angle \theta (radians)‘);
h=Zlabel (‘E(\theta) /\omega‘);
Walter Roberson
am 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.
Akzeptierte Antwort
Walter Roberson
am 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;
x1+x2+x3==420]
sol = solve(eqn,[x1, x2, x3, t], 'maxdegree', 3)
[sol.x1, sol.x2, sol.x3, sol.t]
vpa(ans,10)
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 Kommentare
Walter Roberson
am 17 Jul. 2021
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]
E2 = lhs(eqns)-rhs(eqns)
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
plot(T, sols);
legend({'x1', 'x2', 'x3', 'x_L'});
Despite the graph, the messages tell you there was no solution.
Walter Roberson
am 18 Jul. 2021
There does not appear to be any solution for that system of equations.
Weitere Antworten (1)
Ildeberto de los Santos Ruiz
am 21 Jul. 2021
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 Kommentare
Ildeberto de los Santos Ruiz
am 21 Jul. 2021
Bearbeitet: Ildeberto de los Santos Ruiz
am 21 Jul. 2021
If someone could help me to plot x1 vs t from the information.
Walter Roberson
am 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)
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_13,x2_13] = solve(EQ1,EQ3)
[x1_23,x2_23] = solve(EQ2,EQ3)
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)
X1 = subs([x1_12, x1_13, x1_23], t, tsol(2))
X2 = subs([x2_12, x2_13, x2_23], t, tsol(2))
So far, so good, the pairs of equation seem to check out.
X3 = subs(x3, [x1, x2], [X1(1), X2(1)])
... which is the solution from the first row of solutions I posted in https://www.mathworks.com/matlabcentral/answers/862790-how-to-solve-3-simultaneous-algebraic-equations-with-a-equality-constraint#answer_731385
That is, there is only one real-valued solution to all of the equations simultaneously.
Siehe auch
Kategorien
Mehr zu Formula Manipulation and Simplification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!