I am getting the error as " Not enough input arguments " and " Failure in initial objective function evaluation. FSOLVE cannot continue". Please suggest me possible solutions.
Show older comments
Efu(1)=0;
Efe(1)=0;
landau_levels=@(EF, m, B) ( (1 / (2 * B)) * ((EF^2 / m^2) - 1) );
amuu = 5.0;
amud = 5.0;
amue = 0.511;
amus = 150.0;
hbarc = 197.3271;
fscon = 137.036;
Bcs = ( 3 * (fscon^0.5) * (amus^2) ) / (hbarc^1.5);
Bcu = ( 1.5 * (fscon^0.5) * (amuu^2) ) / (hbarc^1.5);
Bcd = ( 3 * (fscon^0.5) * (amud^2) )/ (hbarc^1.5);
Bce = ( (fscon^0.5) * (amue^2) )/ (hbarc^1.5);
Bc = (5e17 * 1.95e-14);
Bds = Bc / Bcs;
Bdu = Bc / Bcu;
Bdd = Bc / Bcd;
Bde = Bc / Bce;
Efs(1)=400;
Efu_ini= 300;
Efe_ini= 20;
Efd=Efs(1);
nu_u= landau_levels(Efu_ini,amuu,Bdu);
nu_e= landau_levels(Efe_ini,amue,Bde);
nu_d= landau_levels(Efd(1),amud,Bdd);
nu_s= landau_levels(Efs(1),amus,Bds);
pF_u= sqrt( max( (Efu_ini^2 - amuu^2 * (1 + 2 * nu_u * Bdu)), 0) );
pF_e= sqrt( max( (Efe_ini^2 - amue^2 * (1 + 2 * nu_e * Bde)), 0) );
pF_d= sqrt( max( (Efd(1)^2 - amud^2 * (1 + 2 * nu_d * Bdd)), 0) );
pF_s= sqrt( max( (Efs(1)^2 - amus^2 * (1 + 2 * nu_s * Bds)), 0) );
n_u = (2 / (3 * pi^2)) * pF_u^3;
n_e = (2 / (3 * pi^2)) * pF_e^3;
n_d = (2 / (3 * pi^2)) * pF_d^3;
n_s = (2 / (3 * pi^2)) * pF_s^3;
fun= @(n_s, n_u, n_d, n_e, Efu_ini, Efe_ini, Efd) root2d(n_s, n_u, n_d, n_e, Efu_ini, Efe_ini, Efd);
x0=[300,20];
x= fsolve( fun,x0)
function F = root2d(n_s, n_u, n_d, n_e , Efu_ini ,Efe_ini ,Efd)
eq1= (2 / 3) * n_u - (1 / 3) * (n_d + n_s) - n_e ;
eq2= Efu_ini + Efe_ini - Efd ;
end
Answers (2)
It is not clear from your code which variables are meant to be the 2 unknowns, and which are constants. In any case, your fun needs to receive the unknowns as a vector, not as separate arguments.
5 Comments
Arunkarthiheyan
on 8 Apr 2025
I named the unknowns Efu and Efe in function root2d. Now we don't know where these unknowns appear in your subsequent code (at the moment, they appear nowhere). You will have to replace them therein whereever necessary.
Efu_ini= 300;
Efe_ini= 20;
x0 = [Efu_ini,Efe_ini];
x = fsolve(@(x)root2d(x,Efu_ini,Efe_ini),x0)
function res = root2d(x,Efu_ini,Efe_ini)
Efu = x(1);
Efe = x(2);
landau_levels=@(EF, m, B) ( (1 / (2 * B)) * ((EF^2 / m^2) - 1) );
amuu = 5.0;
amud = 5.0;
amue = 0.511;
amus = 150.0;
hbarc = 197.3271;
fscon = 137.036;
Bcs = ( 3 * (fscon^0.5) * (amus^2) ) / (hbarc^1.5);
Bcu = ( 1.5 * (fscon^0.5) * (amuu^2) ) / (hbarc^1.5);
Bcd = ( 3 * (fscon^0.5) * (amud^2) )/ (hbarc^1.5);
Bce = ( (fscon^0.5) * (amue^2) )/ (hbarc^1.5);
Bc = (5e17 * 1.95e-14);
Bds = Bc / Bcs;
Bdu = Bc / Bcu;
Bdd = Bc / Bcd;
Bde = Bc / Bce;
Efs(1)=400;
Efd=Efs(1);
nu_u= landau_levels(Efu_ini,amuu,Bdu);
nu_e= landau_levels(Efe_ini,amue,Bde);
nu_d= landau_levels(Efd(1),amud,Bdd);
nu_s= landau_levels(Efs(1),amus,Bds);
pF_u= sqrt( max( (Efu_ini^2 - amuu^2 * (1 + 2 * nu_u * Bdu)), 0) );
pF_e= sqrt( max( (Efe_ini^2 - amue^2 * (1 + 2 * nu_e * Bde)), 0) );
pF_d= sqrt( max( (Efd(1)^2 - amud^2 * (1 + 2 * nu_d * Bdd)), 0) );
pF_s= sqrt( max( (Efs(1)^2 - amus^2 * (1 + 2 * nu_s * Bds)), 0) );
n_u = (2 / (3 * pi^2)) * pF_u^3;
n_e = (2 / (3 * pi^2)) * pF_e^3;
n_d = (2 / (3 * pi^2)) * pF_d^3;
n_s = (2 / (3 * pi^2)) * pF_s^3;
eq1= (2 / 3) * n_u - (1 / 3) * (n_d + n_s) - n_e ;
eq2= Efu_ini + Efe_ini - Efd ;
res = [eq1,eq2];
end
Arunkarthiheyan
on 9 Apr 2025
Arunkarthiheyan
on 9 Apr 2025
Which variables are the unknowns (I named them Efu and Efe) in this part of the code where the equations to be solved are deduced ? If you don't know what I mean: can you write down the equations you are trying to solve in a mathematical way and mark the two unknowns ?
landau_levels=@(EF, m, B) ( (1 / (2 * B)) * ((EF^2 / m^2) - 1) );
amuu = 5.0;
amud = 5.0;
amue = 0.511;
amus = 150.0;
hbarc = 197.3271;
fscon = 137.036;
Bcs = ( 3 * (fscon^0.5) * (amus^2) ) / (hbarc^1.5);
Bcu = ( 1.5 * (fscon^0.5) * (amuu^2) ) / (hbarc^1.5);
Bcd = ( 3 * (fscon^0.5) * (amud^2) )/ (hbarc^1.5);
Bce = ( (fscon^0.5) * (amue^2) )/ (hbarc^1.5);
Bc = (5e17 * 1.95e-14);
Bds = Bc / Bcs;
Bdu = Bc / Bcu;
Bdd = Bc / Bcd;
Bde = Bc / Bce;
Efs(1)=400;
Efd=Efs(1);
nu_u= landau_levels(Efu_ini,amuu,Bdu);
nu_e= landau_levels(Efe_ini,amue,Bde);
nu_d= landau_levels(Efd(1),amud,Bdd);
nu_s= landau_levels(Efs(1),amus,Bds);
pF_u= sqrt( max( (Efu_ini^2 - amuu^2 * (1 + 2 * nu_u * Bdu)), 0) );
pF_e= sqrt( max( (Efe_ini^2 - amue^2 * (1 + 2 * nu_e * Bde)), 0) );
pF_d= sqrt( max( (Efd(1)^2 - amud^2 * (1 + 2 * nu_d * Bdd)), 0) );
pF_s= sqrt( max( (Efs(1)^2 - amus^2 * (1 + 2 * nu_s * Bds)), 0) );
n_u = (2 / (3 * pi^2)) * pF_u^3;
n_e = (2 / (3 * pi^2)) * pF_e^3;
n_d = (2 / (3 * pi^2)) * pF_d^3;
n_s = (2 / (3 * pi^2)) * pF_s^3;
Star Strider
on 7 Apr 2025
0 votes
Note that ‘F’ is the output of ‘root2d’, however ‘F’ is nowhere defined as a calculation result in that code:
function F = root2d(n_s, n_u, n_d, n_e , Efu_ini ,Efe_ini ,Efd)
eq1= (2 / 3) * n_u - (1 / 3) * (n_d + n_s) - n_e ;
eq2= Efu_ini + Efe_ini - Efd ;
end
That might be something to consider fixing.
.
3 Comments
Matt J
on 7 Apr 2025
Must not be a scalar, I think you mean. It should be,
function F = root2d(_____)
eq1= (2 / 3) * n_u - (1 / 3) * (n_d + n_s) - n_e ;
eq2= Efu_ini + Efe_ini - Efd ;
F=[eq1;eq2];
end
Arunkarthiheyan
on 9 Apr 2025
Star Strider
on 9 Apr 2025
The fsolve function is a root-finder, that is it finds the values of the parameters where the function crosses or equals zero. With your function, fsolve finds a minimum, however it may not be able to find a root.
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!