fzero line 398 error; debugger not solving...
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sergio Quesada
le 15 Oct 2018
Modifié(e) : Sergio Quesada
le 15 Oct 2018
I am having a problem with fzero in this code :
prueba = r_teor (8e-3)
function Arg = r_teor (t0)
FC = 4.24E-1;
a = 6.05;
FD = 8.17E-4;
Io = 15.53;
V = 25.00;
texp=0.009:0.0001:0.0099;
Arg = zeros (N,1); % prellocating
for i = 1 : N
options=optimset('Display','iter','TolX',1e-5);
% Display: off / iter / final / notify
% TolX: Default 2.204 e-16
Arg (i) = fzero (@(r) trapecios (r) - (texp(i)-t0), 5e-3, options);
end
function Int = trapecios(r)
if r <= 1
Int = 0;
return
end
F = @(x) FC .* exp( -(V.*a) ./ (30.*x.*log(x)) );
Int = 0;
part = 1e-3;
L = 1:part:r;
me = F(L);
sum_me = sum (me);
ue = F( max( L ) );
Int = zeros (N,1); % prellocating
i = 1:N;
Int (i) = part.* (sum_me - (ue/2));
end % trapecios
end % r_teor
The error is:
Operands to the || and && operators must be convertible to logical scalar values.
Error in fzero (line 398)
if ~isfinite(fb) || ~isreal(fb) || ~isfinite(b)
, but the debugger sais that both b and fb are real and finite:
K>> b, fb, whos b, whos fb
b =
1.163523750296039
fb =
1.0e-03 *
-0.999999999999276
-0.999999999999276
-0.999999999999276
-0.999999999999276
-0.999999999999276
-0.999999999999276
-0.999999999999276
-0.999999999999276
-0.999999999999276
-0.999999999999276
Name Size Bytes Class Attributes
b 1x1 8 double
Name Size Bytes Class Attributes
fb 10x1 80 double
My function trapecios has no problem when executing it on b = 1.163523750296039.
Could it be because fzero cannot find zeros if the function does not change it sign (as x^2) ? Could it be because I must enter t0 as a 1:10 array (t0 is the variable of r_teor, so how could I do it) ?
Any idea? Thanks !!!
0 commentaires
Réponse acceptée
Steven Lord
le 15 Oct 2018
Function to solve, specified as a handle to a scalar-valued function or the name of such a function. fun accepts a scalar x and returns a scalar fun(x).
Does your function satisfy that requirement? In particular, does it return a scalar fun(x)?
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!