non-linear equation fzero error

5 次查看(过去 30 天)
uzzi
uzzi 2023-5-10
Hello,
I am having this error while solving. I don't know how to fix it. can someone help me?
% Given parameters
d_T = 0.0001; % diameter of thermocouple wire (m)
L_T = 4; % length of thermocouple wire (m)
d_TP = 0.0005; % diameter of thermocouple junction probe (m)
e = 0.20; % emissivity of thermocouple
k = 30; % heat conduction of thermocouple (W/mK)
T_env = 25 + 273.15; % temperature of environment (K)
T_fg = 1190 + 273.15; % temperature of flue gas (K)
T_wall = 400 + 273.15; % temperature of wall (K)
A = 8; % heat transfer coefficient of flue gas (W/(m^2K))
sigma = 5.67e-8; % Stefan-Boltzmann constant (W/(m^2K^4))
% Surface area of thermocouple junction
A_surf = pi * (d_TP/2)^2;
% Equilibrium equation for temperature of thermocouple junction
fun = @(T_tc) A*(T_fg - T_wall) - sigma*e*A_surf*(T_tc^4 - T_env^4) ...
- (L_T/d_T)*k*A_surf*(T_tc - T_wall);
% Solve for temperature of thermocouple junction
T_tc = fzero(fun, [0 T_fg]);
Error using fzero
Function values at the interval endpoints must differ in sign.
% Display result in Celsius
T_tc_C = T_tc - 273.15;
disp(['Temperature of thermocouple junction: ', num2str(T_tc_C), ' C']);
  1 个评论
Dyuman Joshi
Dyuman Joshi 2023-5-10
编辑:Dyuman Joshi 2023-5-10
As the error states, the initial values must have opposite signs, as fzero arrives at a solution iteratively via a combination of methods. (@John D'Errico gave a detailed explaination of the working of fzero in one of their answer, I'll add the link to it if I find it)
From the documentation - Initial values to fzero() - "2-element vector — fzero checks that fun(x0(1)) and fun(x0(2)) have opposite signs, and errors if they do not. It then iteratively shrinks the interval where fun changes sign to reach a solution. An interval x0 must be finite; it cannot contain ±Inf."
Moreover, the function in the given range doesn't cross the x-axis (see figure below) and doesn't have a solution.
% Given parameters
d_T = 0.0001; % diameter of thermocouple wire (m)
L_T = 4; % length of thermocouple wire (m)
d_TP = 0.0005; % diameter of thermocouple junction probe (m)
e = 0.20; % emissivity of thermocouple
k = 30; % heat conduction of thermocouple (W/mK)
T_env = 25 + 273.15; % temperature of environment (K)
T_fg = 1190 + 273.15; % temperature of flue gas (K)
T_wall = 400 + 273.15; % temperature of wall (K)
A = 8; % heat transfer coefficient of flue gas (W/(m^2K))
sigma = 5.67e-8; % Stefan-Boltzmann constant (W/(m^2K^4))
% Surface area of thermocouple junction
A_surf = pi * (d_TP/2)^2;
% Equilibrium equation for temperature of thermocouple junction
fun = @(T_tc) A.*(T_fg - T_wall) - sigma.*e.*A_surf.*(T_tc.^4 - T_env.^4) ...
- (L_T./d_T)*k.*A_surf.*(T_tc - T_wall);
fplot(fun,[0 T_fg])
The nearest solution to T_fg is
sol = fzero(fun, T_fg)
sol = 2.4236e+04
% Solve for temperature of thermocouple junction
T_tc = fzero(fun, [0 T_fg]);
Error using fzero
Function values at the interval endpoints must differ in sign.
% Display result in Celsius
T_tc_C = T_tc - 273.15;
disp(['Temperature of thermocouple junction: ', num2str(T_tc_C), ' C']);

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Optimization 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by