Not able to find fzero

1 回表示 (過去 30 日間)
Dhawal Beohar
Dhawal Beohar 2022 年 5 月 25 日
コメント済み: Dhawal Beohar 2022 年 8 月 7 日
--> difference.m
function y = difference(u,d1,n,a,m,T,PsByN_0,UmaxN_0)
d1=20;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=5;
PsByN_0=10.^(PsByN_0dB/10);
UmaxdB = 5;
UmaxN_0=10.^(UmaxdB/10);
fun1 = (-1./u)*log(((d1^m)./(a*n*PsByN_0*T*u+d1^m)*a)./(1-a));
fun2 = (1./u)*log(((-exp(u*UmaxN_0)*(exp(-PsByN_0*u)))./(u*UmaxN_0+PsByN_0*u))*(PsByN_0*u)-(PsByN_0*u*(exp(-PsByN_0*u)))*(expint(u*UmaxN_0+PsByN_0*u))+(exp(-PsByN_0*u))+((PsByN_0*u)*(exp(-PsByN_0*u)))*(expint(PsByN_0*u))+(exp(u*UmaxN_0))./((UmaxN_0/PsByN_0)+1));
y = (fun1 - fun2);
g0=fzero(@(u) difference(u,d1,n,a,m,T,PsByN_0,UmaxN_0), 10);
end

採用された回答

Torsten
Torsten 2022 年 5 月 25 日
d1=20;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=5;
PsByN_0=10.^(PsByN_0dB/10);
UmaxdB = 5;
UmaxN_0=10.^(UmaxdB/10);
fun1 = @(u) (-1./u)*log(((d1^m)./(a*n*PsByN_0*T*u+d1^m)*a)./(1-a));
fun2 = @(u) (1./u)*log(((-exp(u*UmaxN_0)*(exp(-PsByN_0*u)))./(u*UmaxN_0+PsByN_0*u))*(PsByN_0*u)-(PsByN_0*u*(exp(-PsByN_0*u)))*(expint(u*UmaxN_0+PsByN_0*u))+(exp(-PsByN_0*u))+((PsByN_0*u)*(exp(-PsByN_0*u)))*(expint(PsByN_0*u))+(exp(u*UmaxN_0))./((UmaxN_0/PsByN_0)+1));
fun =@(u) (fun1(u) - fun2(u));
g0=fzero(fun, 10);
  21 件のコメント
Torsten
Torsten 2022 年 8 月 6 日
I suggest you try an interval around the zero you found, e.g.
u = fzero(fun,[0.01,0.02])
U = linspace(0.01,0.02,20);
fU = fun(U);
plot(U,fU)
Dhawal Beohar
Dhawal Beohar 2022 年 8 月 6 日
ok, thanks!

サインインしてコメントする。

その他の回答 (1 件)

Sam Chak
Sam Chak 2022 年 5 月 25 日
Guess the problem that you want to solve is a complex-valued function.
function y = difference(u)
% parameters
d1 = 20;
n = 10^-11.4;
m = 2.7;
a = 0.5;
T = 1;
PsByN_0dB = 5;
PsByN_0 = 10.^(PsByN_0dB/10);
UmaxdB = 5;
UmaxN_0 = 10.^(UmaxdB/10);
% functions
fun1 = (-1./u)*log(((d1^m)./(a*n*PsByN_0*T*u + d1^m)*a)./(1 - a));
fun2 = (1./u)*log(((- exp(u*UmaxN_0)*(exp(-PsByN_0*u)))./(u*UmaxN_0 + PsByN_0*u))*(PsByN_0*u) - (PsByN_0*u*(exp(-PsByN_0*u)))*(expint(u*UmaxN_0 + PsByN_0*u)) + (exp(-PsByN_0*u)) + ((PsByN_0*u)*(exp(-PsByN_0*u)))*(expint(PsByN_0*u)) + (exp(u*UmaxN_0))./((UmaxN_0/PsByN_0) + 1));
y = (fun1 - fun2);
end
Let's try with fzero first.
[u, fval, exitflag, output] = fzero(@(u) difference(u), 10)
The exitflag = -4 indicates that complex function value was encountered while searching for an interval containing a sign change.
Next, fsolve is used.
[u, fval, exitflag, output] = fsolve(@(u) difference(u), 10)
The exitflag = -2 means that the Equation is not solved. The exit message shows that fsolve stopped because the problem appears regular as measured by the gradient, but the vector of function values is not near zero as measured by the default value of the function tolerance.
  5 件のコメント
Torsten
Torsten 2022 年 5 月 25 日
Yes, as said, I plotted the difference and there is no point where the difference is 0.
Dhawal Beohar
Dhawal Beohar 2022 年 8 月 7 日
@Torsten you haven always big help. Can you please look into this problem and help me. Thank you!
https://uk.mathworks.com/matlabcentral/answers/1775175-how-to-store-the-value-of-intersection-points-from-fzero-into-a-vector

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOptimization についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by