Why does solve() parametrize the results in the conditions?

조회 수: 15 (최근 30일)
Magne Lauritzen
Magne Lauritzen 2019년 10월 19일
댓글: Walter Roberson 2019년 10월 20일
Hello, everyone.
This is my first question on MATLAB Answers. I am usually able to find solutions to my MATLAB problems without the need to ask for help, but I have been stuck on this problem for three full days now and I am ready to throw in the towel.
Let me begin by stating my goal. I have a set of six equations with nine variables. This system of equations define the behaviour of a TEC module, also called a Peltier module. My goal is to solve this set of equations by fixing two of the variables and letting one variable be free.
The variables are as follows:
T_h : Hot-side temperature [K]
T_c : Cold-side temperature [K]
DT : Temperature difference between hot-side and cold-side [K]
V_in : Voltage across the TEC [V]
I_in : Current going through the TEC [I]
P_in : Power being used by the TEC [W]
Q_c : Heat being pumped from the cold-side to the hot-side [W]
Q_h : Heat being dumped into the hot-side [W]
COP : Coefficient of performance
The equations are as follows
dt_eq = DT == T_h-T_c;
qc_eq = Q_c == 0.05*T_c*I_in - 1.5*I_in^2 - 0.5*DT;
vin_eq = V_in == 0.05*DT + I_in*1.5;
pin_eq = P_in == V_in*I_in;
qh_eq = Q_h == P_in + Q_c;
cop_eq = COP == Q_c/P_in;
To reiterate: My goal is to fix any two of the variables, leave one free variable, and solve the set of equations for the remaining six variables as a function of the one free variable. This will allow me to investigate the expected behaviour of the Peltier element as a function of any variable and under the conditions which are set by the two fixed variables.
The problem
For certain free variables, I am able to solve the set of equations. However, for many other variables, the solver either returns no solution when there clearly is a solution, or the solutions is annoyingly found as parametrized in the conditions of the returned answer!
As an example, I set up my code as follows (some pseudocode involved):
syms DT Q_c V_in P_in I_in T_h T_c Q_h COP
%Fix two variables.
T_h = 300; %Hot side temperature is 300 Kelvin
Q_c = 1; %Heat pumped from cold-side to hot-side is 1 Watt.
%Equations definitions goes here, see code snippet above
dt_eq = ...
qc_eq = ...etc
%Set assumptions
assume(T_h>0 & T_c>0) %Temperatures in Kelvin cannot be 0 or negative.
assumeAlso(V_in>=0 & I_in>=0) %Equations are not valid for reversed polarity
%Create array of all the equations
equations = [dt_eq, qc_eq, vin_eq, pin_eq, qh_eq, cop_eq]
%Create array of the variables I want to solve for. Note that P_in is missing.
%This is because I want the solutions to be functions of P_in.
variables = [DT V_in I_in T_c Q_h COP]
%Solve equations
sol = solve(equations, variables, 'real', true, 'ReturnConditions', true, 'MaxDegree', 3);
The returned object sol is as follows:
sol =
struct with fields:
DT: [1×1 sym]
V_in: [1×1 sym]
I_in: [1×1 sym]
T_c: [1×1 sym]
Q_h: [1×1 sym]
COP: [1×1 sym]
parameters: [1×6 sym]
conditions: [1×1 sym]
Each variable (DT, V_in, I_in, etc) has become parametrized:
>> pretty(sol.DT)
z1
>> pretty(sol.V_in)
z2
And the actual equations for z1, z2, z3, etc., are found in the conditions together with all the other conditions that the parametrized solutions are valid for. I am not going to post it here because the output is large, so I am attaching it as Conditions.txt.
I am happy with parametrized equations, but why in the world are they defined in the conditions? I do not know how I can reliably and programatically extract the symbolic equations from the definitions.

채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 19일
Your nonnegative and positive constraints together with the ^2 impose boundaries. The equation has to be solved in ways that the constrained values do not go negative (or become 0 for two of them).
The parameterization appears to me to be expressing the boundary conditions for validity of the solution.
I suspect that that the parameterization would mostly disappear if you removed the constraints.
  댓글 수: 2
Magne Lauritzen
Magne Lauritzen 2019년 10월 19일
편집: Magne Lauritzen 2019년 10월 19일
Dear Walter,
Thank you for your answer. I have often seen your insightful replies in MATLAB Answers, and was hoping you would reply to this problem.
You are indeed correct that removing the constrains means the solution does not become parametrized. However, now I have a new problem. Given certain combinations of fixed and free variables, there may be a very large amount of solutions which are valid if no assumptions are placed on the variables.
Example
Take the following example:
T_h = 300 K
DT = 20 K
COP : Free variable
This combination provides five distinct solutions when no assumptions are placed on the variables:
sol =
struct with fields:
Q_c: [5×1 sym]
V_in: [5×1 sym]
P_in: [5×1 sym]
I_in: [5×1 sym]
T_c: [5×1 sym]
Q_h: [5×1 sym]
parameters: [1×0 sym]
conditions: [5×1 sym]
Most of these solutions are not valid when one considers the real-life restrictions that must be imposed on each variable. For example, P_in must be positive under all circumstances, T_h and T_c cannot be negative, etc. Is there a way that I can weed out the solutions which are not valid, given a certain set of assumptions on each variable?
Walter Roberson
Walter Roberson 2019년 10월 20일
mask = sol.P_in > 0 & sol.T_h >= 0;
sol = structfun(@(F) F(mask), sol, 'uniform', 0);

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by