problem with fzero func

4 次查看(过去 30 天)
I Have problem with this part of code it returns the following error 'Function values at interval endpoints must be finite and real.' in the linen where M(m)=fzero(func,x_int).I have the latest version of matlab
%% Pressione in uscita
if (11000>ALT) && (ALT<25000)
T = -56.46; %C
p_o = 1000*(22.65*exp(1.73-0.000157*ALT));
elseif ALT>=25000
T = -131.21 + 0.00299*ALT ;
p_o = 1000*(2.488*((T+273.1)/216.6)^-11.388);
else
T = 15.04 - 0.00649*ALT;
p_o = 1000*(101.29*((T+273.1)/288.08)^5.256);
end
%% Inizio il calcolo
PR = p_o/p_1;
PR2 = (p_o/p_1)^((g-1)/g);
TT = (2*g*R*T_1)/(g-1);
p_t = ((2/(g+1))^(g/(g-1)))*2.068;
v_t = sqrt((2*g*R*T_1)/(g+1));
v_e = sqrt(TT*(1-PR2));
if m_dot==0
m_dot=FT/v_e;
elseif FT==0
FT = m_dot/v_e;
else
fprintf('You can either set desired thrust OR mass flow rate')
end
T_e = T_1*(p_o/p_1)^((g-1)/g);
a_e = sqrt(g*R*T_e);
Me = v_e/a_e;
% Metodi delle caratteristiche
TR = 35; %raggio della gola in cm
RTOD = 180/pi;
DTOR = pi/180;
P = []; %punti sull' asse delle x
%% Parametrizzazione funzione di Prantl meyer
A = sqrt((g+1)/(g-1));
B = (g-1)/(g+1);
v_PM = @(x) A*atan(sqrt(B*(x^2-1))) - atan(sqrt(x^2-1));
%% Calcolo T_max, BREAK UP INTO DIVISIONS
T_max = 0.5*v_PM(Me)*RTOD;
DT = (90-T_max) - fix(90-T_max);
T(1) = DT*DTOR;
n = T_max*2;
for m = 2:T_max*2
T(m) = (DT + (m-1))*DTOR;
%Mach from T(i) using T(i) = v_PM (FALSE POSITION)
x_int = [1 1.01*Me];
func = @(x) T(m) - v_PM(x);
M(m) = fzero(func,x_int);
P(m) = 0 + TR*tan(T(m)); %X-AXIS POINTS
%RRSLOPES
RR(m) = -TR/P(m);
%LR slopes
LR(m) = tan(T(m)+asin(1/M(m)));
SL(m) = -RR(m);
end
  2 个评论
Matt J
Matt J 2021-1-8
For which m in the loop does this occur? Also, have you checked that func(x_int(1)) and func(x_int(2)) are both finite and real, as the error message suggests?
Mathieu NOE
Mathieu NOE 2021-1-8
hello Francesco
would be glad to help , but we miss a bunch of initialisation of data to run this code

请先登录,再进行评论。

采纳的回答

Shiva Kalyan Diwakaruni
Hi,
The error 'Function values at interval endpoints must be finite and real.' could be due to because some of input data could be 'Inf' or some values could be negative which may lead to imaginary values.
Hence you could add a breakpoint at the line containing M(m)=fzero(func,x_int) and try out calling func() with different input values , where at some point would lead to the error and you could handle the case for such input values .
hope it helps,
thanks.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by