Filter löschen
Filter löschen

Matlab giving the warning of Exiting fzero!

5 Ansichten (letzte 30 Tage)
Dhawal Beohar
Dhawal Beohar am 9 Mär. 2022
Bearbeitet: Torsten am 15 Mär. 2022
Exiting fzero: aborting search for an interval containing a sign change
because complex function value encountered during search.
(Function value at -2.8 is 10.0875+1.122i.)
Check function or try again with a different starting value.
I am getting the complex value for any initial value i am giving. How can i solve this issue. I have tried using different values for initial guess and changing some of my input values as well, but no success. Here is my code below. Any help would be really appreciated.
function fval = fun(u)
d1=20;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=25;
PsByN_0=10.^(PsByN_0dB/10);
fun1 = @(u) (((-1./u)*log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T);
initialguess = 10;
zero = fzero(fun1,initialguess);
  1 Kommentar
Walter Roberson
Walter Roberson am 9 Mär. 2022
Nothing in your code assigns to fval .
Your code ignores the u that was passed in to fun. The u in the @(u) definition of fun1 "shadows" the u that was passed in to fun

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 9 Mär. 2022
d1=20;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=25;
PsByN_0=10.^(PsByN_0dB/10);
fun1 = @(u) (((-1./u)*log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T);
syms U
F = fun1(U)
F = 
In order for that to be 0, either is infinite or the log() has to be 0 . But for the log() to be 0, the value inside would have to be 1
inner = children(children(F, 2),1)
inner = 
Ubest = solve(inner == 1)
Ubest = 
fun1(Ubest)
ans = 
0
vpa(Ubest)
ans = 
  8 Kommentare
Dhawal Beohar
Dhawal Beohar am 15 Mär. 2022
Thanks, How it can be done using fzero? It is giving answer as NaN
Torsten
Torsten am 15 Mär. 2022
Bearbeitet: Torsten am 15 Mär. 2022
Then you'll have to vary the initial u0 until you get a reasonable solution.
If it works with "fsolve", why don't you use it ?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Optimization finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by