non-numerical answer for solving complex non-linear equation
2 次查看(过去 30 天)
显示 更早的评论
Hello, I am trying to sollve for T_TP according to the following equation. I used "solve" but as for the answer, I am not getting numerical value and I am getting the answer with the variables. Can someone help me?
d_T = 0.0001; % diameter of thermocouple junction (m)
L = 4; % length of thermocouple (m)
d_TP = 0.0005; % outer diameter of thermocouple sheath (m)
emi = 0.20; % emissivity of thermocouple
k = 30; % heat conduction of thermocouple (W/mK)
T_env = 25+273.15; % environment temperature (°C)
T_fg = 1190+273.15; % flue gas temperature (°C)
T_wall = 1350+273.15; % wall temperature (°C)
alpha = 8; % heat transfer coefficient of flue gas (W/m^2K)
Sigma=5.67e-8;
syms d_T L d_TP emi k T_env T_fg T_wall alpha Sigma T_TP
eq1 = ((pi*d_TP^2)/4) * emi* Sigma* (T_fg^4 - T_TP^4);
eq2 = ((pi*d_TP^2)/4) * alpha* (T_fg - T_TP);
eq3 = ((pi*d_TP^2)/4) * emi* Sigma* (T_TP^4 - T_wall^4);
eq4 = ((pi*d_T^2)/4) * (k/L) * (T_TP - T_env);
sol = solve([eq1+eq2 == eq3+eq4],[T_TP])
0 个评论
采纳的回答
Star Strider
2023-5-19
编辑:Star Strider
2023-5-19
You define all the variables numerically, however your code then declares them as symbolic.
The easy solution is simply to put the syms call before the numerical assignments —
syms d_T L d_TP emi k T_env T_fg T_wall alpha Sigma T_TP
d_T = 0.0001; % diameter of thermocouple junction (m)
L = 4; % length of thermocouple (m)
d_TP = 0.0005; % outer diameter of thermocouple sheath (m)
emi = 0.20; % emissivity of thermocouple
k = 30; % heat conduction of thermocouple (W/mK)
T_env = 25+273.15; % environment temperature (°C)
T_fg = 1190+273.15; % flue gas temperature (°C)
T_wall = 1350+273.15; % wall temperature (°C)
alpha = 8; % heat transfer coefficient of flue gas (W/m^2K)
Sigma=5.67e-8;
% syms d_T L d_TP emi k T_env T_fg T_wall alpha Sigma T_TP
eq1 = ((pi*d_TP^2)/4) * emi* Sigma* (T_fg^4 - T_TP^4);
eq2 = ((pi*d_TP^2)/4) * alpha* (T_fg - T_TP);
eq3 = ((pi*d_TP^2)/4) * emi* Sigma* (T_TP^4 - T_wall^4);
eq4 = ((pi*d_T^2)/4) * (k/L) * (T_TP - T_env);
sol = solve([eq1+eq2 == eq3+eq4],[T_TP])
vpasol = vpa(sol)
format longE
doublesol = double(sol)
EDIT — Corrected typographical errors.
.
4 个评论
John D'Errico
2023-5-19
编辑:John D'Errico
2023-5-19
Sadly, what you don't understand is that while it did give you numerical ansers, you do not understand what you did, or what was happening.
The pre-definition of those variables as syms had ABSOLUTELY NO IMPACT on the result. It did not create symbolic variables that were then used. In fact, it just wasted CPU cycles.
更多回答(1 个)
John D'Errico
2023-5-19
编辑:John D'Errico
2023-5-19
I think you do not understand how variables work in MATLAB. Variables are dynamically assigned. When you assign them as you have done, the last assignment takes precendent, completely overwriting the previous variable.
For example,
a = 1;
whos a
So a is a double. It has the value 1.
But now, if I use syms to define a, what happens?
syms a
whos a
a is now a symbolic variable. It no longer has the value 1 anymore. a is just a, an unknown variable. We overwrote the original double precision variable with a new symbolic variable. What we did not do was convert the value a into a symbolic variable that contains the number 2.
Similarly, if you create a variable b, using syms
syms b
whos b
But now assign b to have a value like this:
b = 2;
whos b
So b is no longer symbolic! I have replaced it with the number 2, and b is now a double.
Let me try one more thing.
c = sym(2)
whos c
Do you see that sym allows me to explicitly assign the value 2 to a symbolic variable, named c? We can work with it, and MATLAB has stored 2 in the variable c, but in symbolic form.
c + 1
Now, what did you do? You made the first mistake I show above.
Can you take a double precision variable, and convert it into a symbolic one, that contains that number?
d = 4 % d is a double
There would be multiple ways to do this operation. You might use cast.
d = cast(d,'sym')
whos d
Another way to do it is to assign using an index. For example:
syms e
whos e
e(1) = 5
whos e
Do you see the difference? By assignming one element of e to be the number 5, MATLAB automatically performs the cast of that value into the variable e. Even though e is a scalar, using the index makes it work, as if I had used cast or sym directly.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!