Solve two equations for one variable

Hello everyone!
I am having problems to solve a simple system of two equations for a single variable. The equations look like:
It is possible to analytically calculate the solution for through the following steps:
  • Isolate in the second equation and replace it in the first equation:
  • Then using the fact that
  • Then, isolating :
  • Finally:
Using MATLAB Symbolic Toolbox, I wrote the following piece of code in order to find the same analytical solution:
syms P_st vdq_st_abs Vabs delta_st Vangle Xg Q_st
eq1 = P_st - vdq_st_abs * Vabs * sin(delta_st - Vangle) / Xg == 0;
eq2 = (Q_st * Xg - Vabs^2)/(Vabs * cos(delta_st - Vangle)) - vdq_st_abs == 0;
eqs = [eq1; eq2];
sol = solve(eqs, delta_st);
Warning: Solutions are parameterized by the symbols: z. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
disp(sol)
z
However, the output is parameterized, and I do not understand it very well. Could someone explain me this parametrization? Also, why can't MATLAB output the same analytical solution I just mentioned?
Thank you very much in advance!

Answers (1)

syms P_st vdq_st_abs Vabs delta_st Vangle Xg Q_st real
eq1 = P_st - vdq_st_abs * Vabs * sin(delta_st - Vangle) / Xg == 0;
eq2 = (Q_st * Xg - Vabs^2)/(Vabs * cos(delta_st - Vangle)) == vdq_st_abs;
eqn = lhs(eq1) * lhs(eq2) == 0;
sol = solve(eqn,delta_st,'ReturnConditions',1)
sol = struct with fields:
delta_st: [2×1 sym] parameters: k conditions: [2×1 sym]
sol.delta_st
ans = 
sol.conditions
ans = 

4 Comments

Thank you very much for your help! However, it is still not clear why does the output solution is not the same as the analytical solution that I provided in my question.
sin^2 and 1-cos^2 also look different, but are equal ...
Did you test the results with numerical values for the parameters ?
I wonder how the two equations can have a common solution for delta_st. You can solve each equation separately and you get two different results. I think you must have misunderstood something:
P_st = 1.0;
vdq_st_abs = 1.0;
Vabs = 1.0;
Vangle = 1.0;
Xg = 1.0;
Q_st = 1.0;
delta_st = Vangle + atan(P_st/(Q_st+Vabs^2/Xg))
delta_st = 1.4636
P_st - vdq_st_abs * Vabs * sin(delta_st - Vangle) / Xg
ans = 0.5528
(Q_st * Xg - Vabs^2)/(Vabs * cos(delta_st - Vangle)) - vdq_st_abs
ans = -1
Thus none of the equations gives 0 for delta_st = Vangle + atan(P_st/(Q_st+Vabs^2/Xg))
My guess is this is what you want:
syms P_st vdq_st_abs Vabs delta_st Vangle Xg Q_st real
eq1 = P_st - vdq_st_abs * Vabs * sin(delta_st - Vangle) / Xg == 0;
eq2 = (Q_st * Xg - Vabs^2)/(Vabs * cos(delta_st - Vangle)) == vdq_st_abs;
S = solve([eq1,eq2],[delta_st,vdq_st_abs])
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
S = struct with fields:
delta_st: [2×1 sym] vdq_st_abs: [2×1 sym]
simplify(S.delta_st(1))
ans = 
simplify(S.delta_st(2))
ans = 
Thank you very much for your help. I didn't try to test the results with numerical values, but since you already stated it doesn't give the expected solution, it is very likely I don't have enough understanding of my equations. However, I edited the original post to show that the expression I mentioned is indeed a solution for both equations. Maybe there is a calculation mistake, or this is one of the multiple possible solutions?
Of course, if I use the last equation of my step-by-step, MATLAB is able to find the desired solution, but I wonder if this is the only way of finding this solution.
syms P_st vdq_st_abs Vabs delta_st Vangle Xg Q_st real
eq1 = P_st - (Q_st + Vabs^2/Xg)*tan(delta_st - Vangle) == 0;
sol = solve(eq1,delta_st)
sol = 

Sign in to comment.

Asked:

on 18 Jul 2023

Commented:

on 19 Jul 2023

Community Treasure Hunt

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

Start Hunting!