How to solve simultaneous equations?

조회 수: 13 (최근 30일)
Valter Silva Nava
Valter Silva Nava 2021년 2월 14일
댓글: Valter Silva Nava 2021년 2월 14일
Hello,
How can I solve a non linear system of three equations with three variables? There is a variable raised to the fourth power that complicates the system. That is why I tried to get a only true solution using, 'PrincipalValue'.
Thanks for the help.
syms x y z
eqn1 = 1500*(20-x)+1.5309E-05*(293^4-(x+273)^4) == z;
eqn2 = 20000*(x-y) == z;
eqn3 = 3600*(y-10)+1.5309E-05*((y+273)^4-100^4) == z;
eqns = [eqn1,eqn2,eqn3];
vars = [x y z];
[solx, soly, solz] = solve(eqns, vars, 'PrincipalValue',true)

채택된 답변

Walter Roberson
Walter Roberson 2021년 2월 14일
syms x y z
eqn1 = 1500*(20-x)+1.5309E-05*(293^4-(x+273)^4) == z;
eqn2 = 20000*(x-y) == z;
eqn3 = 3600*(y-10)+1.5309E-05*((y+273)^4-100^4) == z;
eqns = [eqn1,eqn2,eqn3];
vars = [x y z];
sol = solve(eqns, vars, 'returnconditions',true)
sol = struct with fields:
x: [16×1 sym] y: [16×1 sym] z: [16×1 sym] parameters: [1×0 sym] conditions: [16×1 sym]
16 solutions.
sol.conditions
ans = 
and they are unconditional.
So there are 16 "true" solutions.
Perhaps you only want real-valued ones?
vx = vpa(sol.x); vy = vpa(sol.y); vz = vpa(sol.z);
mask = imag(vx) == 0 & imag(vy) == 0 & imag(vz) == 0;
realx = vx(mask);
realy = vy(mask);
realz = vz(mask);
([realx, realy, realz])
ans = 
So there are two "true" solutions that also happen to be real-valued. This was predictable: degree 16 polynomials in real roots always have an even number of real roots.
If you wanted to ignore some of the valid solutions even further, you could further test realx > 0
  댓글 수: 2
Walter Roberson
Walter Roberson 2021년 2월 14일
I would, by the way, point out that asking for exact solutions to systems with floating point coefficients is like asking for exactly how many molecules are in a bottle of beer that is "about" half-full. (How big is the bottle, exactly ? How close to "half full" is "about" half full, exactly ?). It is is a category error to use solve() with any equations with floating point coefficients.
eqn1 = 1500*(20-x)+1.5309E-05*(293^4-(x+273)^4) == z;
273 ? really?? You give 5 significant digits to 1.5309, so why did you only give 3 significant digits to 273 and 293? 0 C is 273.1600(1) K https://en.wikipedia.org/wiki/Kelvin -- 293.16 exactly until 2019.
What is the point of asking for exact solutions to equations that are wrong?
Valter Silva Nava
Valter Silva Nava 2021년 2월 14일
Thanks for the answer, I will analyze it and understand all the comments that you made. In a second try I used "vpasolve" and showed me all the solutions and with the last part that you answered I could get only the real solutions. Thanks again.
syms x y z
eqn1 = 1500*(20-x)+1.5309E-05*(293.1600^4-(x+273.1600)^4) == z;
eqn2 = 20000*(x-y) == z;
eqn3 = 3600*(y-10)+1.5309E-05*((y+273.1600)^4-100^4) == z;
eqns = [eqn1 eqn2 eqn3];
vars = [x y z];
solution = vpasolve(eqns, vars);
solution.x
solution.y
solution.z
vx = vpa(solution.x); vy = vpa(solution.y); vz = vpa(solution.z);
mask = imag(vx) == 0 & imag(vy) == 0 & imag(vz) == 0;
realx = vx(mask); realy = vy(mask); realz = vz(mask);
([realx, realy, realz])

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by