non-numerical answer for solving complex non-linear equation

5 views (last 30 days)
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])
sol = 

Accepted Answer

Star Strider
Star Strider on 19 May 2023
Edited: Star Strider on 19 May 2023
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])
sol = 
vpasol = vpa(sol)
vpasol = 
format longE
doublesol = double(sol)
doublesol =
1.546247219949594e+03 + 0.000000000000000e+00i 3.650226045888263e+01 - 1.583591092350079e+03i 3.650226045888263e+01 + 1.583591092350079e+03i -1.619251740867359e+03 + 0.000000000000000e+00i
EDIT — Corrected typographical errors.
.
  4 Comments
John D'Errico
John D'Errico on 19 May 2023
Edited: John D'Errico on 19 May 2023
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.

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 19 May 2023
Edited: John D'Errico on 19 May 2023
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
Name Size Bytes Class Attributes a 1x1 8 double
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
Name Size Bytes Class Attributes a 1x1 8 sym
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
Name Size Bytes Class Attributes b 1x1 8 sym
But now assign b to have a value like this:
b = 2;
whos b
Name Size Bytes Class Attributes b 1x1 8 double
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)
c = 
2
whos c
Name Size Bytes Class Attributes c 1x1 8 sym
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
ans = 
3
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
d = 4
There would be multiple ways to do this operation. You might use cast.
d = cast(d,'sym')
d = 
4
whos d
Name Size Bytes Class Attributes d 1x1 8 sym
Another way to do it is to assign using an index. For example:
syms e
whos e
Name Size Bytes Class Attributes e 1x1 8 sym
e(1) = 5
e = 
5
whos e
Name Size Bytes Class Attributes e 1x1 8 sym
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.
  1 Comment
uzzi
uzzi on 19 May 2023
At first, I didn't understand the meaning of "syms" and I used according to a Youtube video. Thank you for the explanation, now I understood

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!