--> 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

 Accepted Answer

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 Comments

Exiting fzero: aborting search for an interval containing a sign change
because complex function value encountered during search.
(Function value at -2.8 is 9.2614+1.122i.)
Check function or try again with a different starting value.
This is what I am getting.Not sure how to proceed further.
Plotting the function, I don't see a real root.
Try
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));
u=0.01:0.01:10;
plot(u,fun(u))
How to analyse the graph...i got this..should I try different for values of u?
No. For that a solution u for your equation exists, the graph had to cross the line y=0, but it doesn't.
Yes, it's not crossing 0. So, what possible mistake I am doing. What do you suggest doing?
Check the parameters and the functions.
I changed parameters and now it seems to be crossing y=0.
Then try
g0=fzero(fun, [0.001 0.1]);
giving this error
Error using fzero
Function values at the interval endpoints must differ in sign.
Torsten
Torsten on 25 May 2022
Edited: Torsten on 25 May 2022
Use the plot to determine ul, ur such that fun(ul) * fun(ur) < 0. Then call fzero as
g0=fzero(fun, [ul,ur]);
Version - R2022a
d1=20;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=15;
PsByN_0=10.^(PsByN_0dB/10);
UmaxdB = 5;
UmaxN_0=10.^(UmaxdB/10);
really sorry but I did'nt understood what you said. What is ul and ur?
Torsten
Torsten on 25 May 2022
Edited: Torsten on 25 May 2022
d1=20;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=15;
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,[0.01,0.02])
% gives g0 = 0.016736
By keeping this value as u in equation fun1 and fun2, I am getting these values
fun1 =
0
fun2 =
0.5825
not equal, but close.
If I add the two lines
fun1(g0)
fun2(g0)
to the code above, I get as output
ans = 1.9901e-14
ans = 1.3268e-14
thus both fun1 and fun2 seem to be approximately 0.
I am getting these values, not sure how it's different for fun2
ans = 1.9901e-14
ans = 2.6535e-14
You want to find u that makes fun(u) = 0.
fun(u) is equal to fun1(u) - fun2(u).
Now you found an u for which fun(u) = fun1(u) - fun2(u) = 1.9901e-14 - 2.6535e-14 = -6.634e-15.
I think you will admit that this is approximately zero.
I agree Torsten, Thank you for the help. You were so much help to me and learnt a lot from you.
Dhawal Beohar
Dhawal Beohar on 6 Aug 2022
Edited: Dhawal Beohar on 6 Aug 2022
@Torsten Hi! quick question, we found for what value of 'u' fun1 = fun2. But how we can find optimal range of 'u' if we want to plot fun1 or fun2 against 'u'.
Thanks in advance.
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)
ok, thanks!

Sign in to comment.

More Answers (1)

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 Comments

then how it can be further solved? what can be the solution.
Apparently, the function does not have any real root, for which the function equals zero.
Thus, it is not surprising that fzero and fsolve cannot solve the given equation.
What exactly are you trying to solve? Or, put it another way, what is the expected solution?
Perhaps there are missing information in the given difference function. Please double check.
Dhawal Beohar
Dhawal Beohar on 25 May 2022
Edited: Dhawal Beohar on 25 May 2022
i wanted to know that for what value of u both the equations i.e., fun1 and fun2 becomes equal....
thank you much for the inputs but my equations are correct but dont know why the solution is not coming.
Yes, as said, I plotted the difference and there is no point where the difference is 0.
@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

Sign in to comment.

Categories

Products

Release

R2022a

Tags

Community Treasure Hunt

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

Start Hunting!