I am trying to solve fsolve (multi-variable) but getting an error.

function fval = func4uo(u)
d1=1;
n=1;
m=1;
a=1;
T=1;
PsByN_0=1;
fval = ((-1/u)*log((d1^m)/(a*n*PsByN_0*T*u)+d1^m)*a*T)/(1-a)*T;
xsol = fsolve (@(u) func4uo(u), 0)
ERROR: Not enough input arguments.

14 commentaires

That's not what is shown when we run the code here,
xsol = fsolve (@(u) func4uo(u), 0)
Error using fsolve (line 300)
Objective function is returning undefined values at initial point. FSOLVE cannot continue.
function fval = func4uo(u)
d1=1;
n=1;
m=1;
a=1;
T=1;
PsByN_0=1;
fval = ((-1/u)*log((d1^m)/(a*n*PsByN_0*T*u)+d1^m)*a*T)/(1-a)*T;
end
How it can be solved?
vectorize your code. u is a vector and you calculate something using it, and you / that against another vector calculated from u. The / operator is not element-by-element division, which is the ./ operator
Dhawal Beohar
Dhawal Beohar le 16 Fév 2022
Modifié(e) : Dhawal Beohar le 16 Fév 2022
I have corrected my code with values of variables and as you have suggested, but still I am having same error. I am not sure I have vectorized correctly.
function fval = func4uo(u)
d1=10;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=20;
PsByN_0=10.^(PsByN_0dB/10);
fval (1,1) = ((-1./u)*log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T;
x0 = [0];
xsol = fsolve (@(u) func4uo(u), 0)
Torsten
Torsten le 16 Fév 2022
Modifié(e) : Torsten le 16 Fév 2022
In the calculation of fval(1,1), you divide by u which is 0 for your initial guess.
Why do you prescribe x0=[0;0;0] (3 unknowns) and in the call to fsolve use x0=0 (1 unknown) ?
Dhawal Beohar
Dhawal Beohar le 16 Fév 2022
Modifié(e) : Dhawal Beohar le 16 Fév 2022
Hi Torsten ! I was not sure I am vectroizing the equation correctly, I have corrected now.
The problem is that you divide by u (fval(1,1) = -1./u ... ) and u = 0 at the beginning.
Try
function main
u0=1;
usol = fsolve(@func4uo,u0)
end
function fval = func4uo(u)
d1=10;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=20;
PsByN_0=10.^(PsByN_0dB/10);
fval (1,1) = ((-1./u)*log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T;
end
But the solution of your problem is obvious:
u = (1-d1^m)/(d1^m*a*n*PsByN_0*T)
Thanks for all the help.
My problem is I am having two equations:
((-1/u)*log((d1^m)/(a*n*PsByN_0*T*u)+d1^m)*a*T)/(1-a)*T
and
(1/u)*log(expint(-Ps*u))*exp(-Ps*u)
I need to find out for what value of u, both of the equations can be equal?
I really apreciate your help.
Then determine the zero of
((-1/u)*log((d1^m)/(a*n*PsByN_0*T*u)+d1^m)*a*T)/(1-a)*T - (1/u)*log(expint(-Ps*u))*exp(-Ps*u)
still anything is wrong?
function fval = func4uo(u)
d1=10;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=20;
PsByN_0=10.^(PsByN_0dB/10);
fval(1,1) = ((-1./u)*log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T - (1./u)*log(expint(-Ps*u))*exp(-Ps*u);
zero = fzero(fval,0)
function main
u0 = 1;
u = fzero(@func4uo,u0)
end
function fval = func4uo(u)
d1=10;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=20;
PsByN_0=10.^(PsByN_0dB/10);
fval = log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T + log(expint(-Ps*u))*exp(-Ps*u);
end
Thanks Torsten for your help...
I have saved the file name as func4uo.m, getting an error:
>> func4uo
Error: File: func4uo.m Line: 41 Column: 1
Function 'func4uo' has already been declared within this scope.
Torsten
Torsten le 17 Fév 2022
Modifié(e) : Torsten le 17 Fév 2022
Save the file as main.m and run it after assigning a value to Ps.
Thanks ! but some other errors,
function main
u0 = 1;
u = fzero(@func4uo,u0)
end
function fval = func4uo(u)
d1=10;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=20;
PsByN_0=10.^(PsByN_0dB/10);
fval = ((-1./u)*log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T - (1./u)*log(expint(-PsByN_0*u))*exp(-PsByN_0*u);
end
Error using fzero (line 328)
Function value at starting guess must be finite and real.
Error in main (line 39)
u = fzero(@func4uo,u0)

Connectez-vous pour commenter.

 Réponse acceptée

By choosing a=1, you are dividing by 1-a=0 for any input value, u.
f(0), f(1), f(2)
ans = -Inf
ans = -Inf
ans = -Inf
function fval = f(u)
d1=1;
n=1;
m=1;
a=1;
T=1;
PsByN_0=1;
fval = ((-1/u)*log((d1^m)/(a*n*PsByN_0*T*u)+d1^m)*a*T)/(1-a)*T;
end

Plus de réponses (2)

There is no zero for that function.
If you use negative u, then the imaginary component of the function approaches negative infinity as u gets close to zero, and only reaches zero again as u gets to -infinity.
If you use positive u and floating point values, then the expint() overflows to infinity when you reach about 8, and the exp() term numerically goes to 0 in floating point, and inf*0 is nan.
If you use positive u with the symbolic toolbox, you can show that the real part of the function is negative until infinity is reached.
Or perhaps I should say that the root is u = +inf as in the limit the function does become 0.
format long g
U = linspace(5,8);
Z = func4uo(U);
figure(); plot(U, real(Z), 'k'); title('real'); xlim([0 10])
figure(); plot(U, imag(Z), 'r'); title('imaginary'); xlim([0 10])
func4uo(10)
ans =
NaN + NaNi
func4uo(sym(10))
ans = 
vpa(ans)
ans = 
syms u
Z = func4uo(u)
Z = 
limit(Z, u, inf)
ans = 
0
vpa(ans)
ans = 
0.0
function fval = func4uo(u)
d1=10;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=20;
PsByN_0=10.^(PsByN_0dB/10);
fval = ((-1./u).*log((d1.^m)./(a.*n.*PsByN_0.*T.*u)+d1.^m).*a.*T)./(1-a).*T - (1./u).*log(expint(-PsByN_0.*u)).*exp(-PsByN_0.*u);
end

1 commentaire

Thanks Walter for the help and explanation. I might need to check equation again.

Connectez-vous pour commenter.

Z = @(PS) arrayfun(@(ps) fzero(@(u)func4uo(u,ps), [0.6775499178144678 1e3]), PS)
Z = function_handle with value:
@(PS)arrayfun(@(ps)fzero(@(u)func4uo(u,ps),[0.6775499178144678,1e3]),PS)
P = linspace(-5, 1);
syms u
F = func4uo(u, P(1))
F = 
string(F)
ans = "- log(692455071077987426423013376/(275018307117627*u) + 2204244764264291/4398046511104)/u - (exp(5*u)*log(expint(5*u)))/u"
%vpasolve(F)
%{
U = Z(P);
plot(P, real(U), 'k', P, imag(U), 'r');
xlabel('Ps'); ylabel('u')
%}
function fval = func4uo(u,Ps)
d1=10;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=20;
PsByN_0=10.^(PsByN_0dB/10);
fval = ((-1./u).*log((d1^m)./(a.*n.*PsByN_0.*T.*u)+d1.^m).*a.*T)./(1-a).*T - (1./u).*log(expint(-Ps.*u)).*exp(-Ps.*u);
end

5 commentaires

Hi Walter, appreciate your help. I need to find out for what value of u, both of the equations can be equal?
I am still having error 'Not enough input arguments'.
You need to define Ps.
I am having difficulty finding Ps values that balance.
I have now corrected the equtaion.
I need to find out for what value of u, both of the equations can be equal?
ERROR: Not enough input arguments.
d1=10;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=20;
PsByN_0=10.^(PsByN_0dB/10);
fval (1,1) = ((-1./u)*log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T - (1./u)*log(expint(-PsByN_0*u))*exp(-PsByN_0*u);
zero = fzero(fval,0)
function fval = func4uo(u)
d1=10;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=20;
PsByN_0=10.^(PsByN_0dB/10);
fval (1,1) = ((-1./u)*log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T - (1./u)*log(expint(-PsByN_0*u))*exp(-PsByN_0*u);
zero = fzero(fval,0)
have you done any changes? Sorry I am not able to find any change....
I am facing below error:
Not enough input arguments.
Error in func4uo (line 47)
fval (1,1) = ((-1./u)*log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T - (1./u)*log(expint(-PsByN_0*u))*exp(-PsByN_0*u);
function fval = func4uo(u)
d1=10;
n=10^-11.4;
m=2.7;
a=0.5;
T=1;
PsByN_0dB=20;
PsByN_0=10.^(PsByN_0dB/10);
fval (1,1) = ((-1./u)*log((d1^m)./(a*n*PsByN_0*T*u)+d1^m)*a*T)./(1-a)*T - (1./u)*log(expint(-PsByN_0*u))*exp(-PsByN_0*u);
zero = fzero(fval,0)
In your other Question I show that your revised code has no root (unless you count u = infinity)

Connectez-vous pour commenter.

Catégories

Produits

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by