eqn solver could not solve my specific seqn
Afficher commentaires plus anciens
Hi all,
Hope you are good.
I have a question about eqn solver. I have an array of constants for a variable and for this I created a for loop which works well but since my eqn is non-linear It does not solve it. Here is my code;
syms Vs Vg p k d Vfb
load b1mhz.txt
Vg = b1mhz(:,1);
prompt = 'k(dielectric constant) :';
k = input(prompt)
prompt = 'p(doping const.) :';
p = input(prompt)
prompt = 'd(thickness in cm) :';
d = input(prompt)
prompt = 'Vfb(V) :';
Vfb = input(prompt)
for i = 1:length(Vg)
Sol{i} = vpa(solve(Vg - Vfb - Vs - (11.7/k)*((2*0.026*p*1.6*10^-19)/(11.7*8.85*10^-14))^0.5*(d*11.7/k)*(exp(-Vs/0.026)+(Vs/0.026)-1+(1.5*10^10/p)^2*(exp(Vs/0.026)-(Vs/0.026)-1))^0.5 == 0,Vs));
end
Vg is my variable and I am stuck right now. I appreciate any help.
Best Regards,
Hasan
3 commentaires
Rameen Zia
le 27 Fév 2021
Will anyone can tell is it easy to use as i m not of computer
Walter Roberson
le 27 Fév 2021
Could you expand on the question?
Tatti Singh
le 28 Fév 2021
Thanks it helped
Réponses (4)
Walter Roberson
le 8 Fév 2021
guess = 1;
for i = 1:length(Vg)
Sol{i} = vpasolve(Vg - Vfb - Vs - (11.7/k)*((2*0.026*p*1.6*10^-19)/(11.7*8.85*10^-14))^0.5*(d*11.7/k)*(exp(-Vs/0.026)+(Vs/0.026)-1+(1.5*10^10/p)^2*(exp(Vs/0.026)-(Vs/0.026)-1))^0.5 == 0,Vs, guess);
%make it easier for the next iteration by starting at the solution for this iteration
if ~isempty(Sol{i}); guess = Sol{i}; end
end
4 commentaires
Hasan canar
le 8 Fév 2021
Walter Roberson
le 8 Fév 2021
syms Vs
guess = 1;
for i = 1:length(Vg)
Sol{i} = vpasolve(Vg(i) - Vfb - Vs - (11.7/k)*((2*0.026*p*1.6*10^-19)/(11.7*8.85*10^-14))^0.5*(d*11.7/k)*(exp(-Vs/0.026)+(Vs/0.026)-1+(1.5*10^10/p)^2*(exp(Vs/0.026)-(Vs/0.026)-1))^0.5 == 0, Vs, guess);
%make it easier for the next iteration by starting at the solution for this iteration
if ~isempty(Sol{i}); guess = Sol{i}; end
end
Notice that I used vpasolve() whereas you used vpa(solve()) which will not work for this situation.
Also I did not notice before that your Vg was a vector, which is something that would have caused your solve() to fail.
Hasan canar
le 8 Fév 2021
Walter Roberson
le 10 Fév 2021
syms Vs
guess = 1;
for i = 1:length(Vg)
thissol = vpasolve(Vg(i) - Vfb - Vs - (11.7/k)*((2*0.026*p*1.6*10^-19)/(11.7*8.85*10^-14))^0.5*(d*11.7/k)*(exp(-Vs/0.026)+(Vs/0.026)-1+(1.5*10^10/p)^2*(exp(Vs/0.026)-(Vs/0.026)-1))^0.5 == 0, Vs, guess);
%make it easier for the next iteration by starting at the solution for this iteration
if isempty(thissol)
Sol(i) = nan;
else
Sol(i) = thissol;
guess = thissol;
end
end
Hasan canar
le 9 Fév 2021
3 commentaires
Walter Roberson
le 9 Fév 2021
The code I posted cannot return the answers you show.
- my code returns a cell array, your code has a regular array
- my code returns empty cells when a solution cannot be found, rather than leaving an unresolved solution
To get the output you show, you would need to be using different code using solve() instead of vpasolve, and also having a couple of other bugs.
Hasan canar
le 10 Fév 2021
Modifié(e) : Hasan canar
le 10 Fév 2021
Walter Roberson
le 10 Fév 2021
It is possible for vpasolve() to be unable to find a solution from a given starting point. However, in such cases, solve() usually cannot do any better. With the expression you are trying to work with, I can nearly guarantee that solve() cannot do any better than vpasolve(), and solve() is more likely to give up.
The general solution has at least two nested nonlinear roots -- that is, the solution requires finding the roots of one nonlinear equation, and the values found become part of the coefficients of another nonlinear equation that has to be solved. There is a third level too that is a quadratic equation that you have to find a specific root of, which you can do when you know specific numeric values for the input() prompts
Hasan canar
le 11 Fév 2021
0 votes
22 commentaires
Walter Roberson
le 11 Fév 2021
We could do better if there were constraints on the range of answers. For example is it known that the solution must be real-valued? Is it always going to be positive? Is it bigger than a bread box?
syms Vs
guess = 1;
maxtries = 10;
for i = 1:length(Vg)
%try once using the last value that worked
thissol = vpasolve(Vg(i) - Vfb - Vs - (11.7/k)*((2*0.026*p*1.6*10^-19)/(11.7*8.85*10^-14))^0.5*(d*11.7/k)*(exp(-Vs/0.026)+(Vs/0.026)-1+(1.5*10^10/p)^2*(exp(Vs/0.026)-(Vs/0.026)-1))^0.5 == 0, Vs, guess);
if isempty(thissol)
%if that did not work, try using random starting points
for trynum = 1 : maxtries - 1
thissol = vpasolve(Vg(i) - Vfb - Vs - (11.7/k)*((2*0.026*p*1.6*10^-19)/(11.7*8.85*10^-14))^0.5*(d*11.7/k)*(exp(-Vs/0.026)+(Vs/0.026)-1+(1.5*10^10/p)^2*(exp(Vs/0.026)-(Vs/0.026)-1))^0.5 == 0, Vs, 'random');
if ~isempty(thissol); break; end
end
end
if isempty(thissol)
Sol(i) = nan;
else
Sol(i) = thissol;
%make it easier for the next iteration by starting at the solution for this iteration
guess = thissol;
end
end
Hasan canar
le 11 Fév 2021
Walter Roberson
le 11 Fév 2021
thissol = vpasolve(Vg(i) - Vfb - Vs - (11.7/k)*((2*0.026*p*1.6*10^-19)/(11.7*8.85*10^-14))^0.5*(d*11.7/k)*(exp(-Vs/0.026)+(Vs/0.026)-1+(1.5*10^10/p)^2*(exp(Vs/0.026)-(Vs/0.026)-1))^0.5 == 0, Vs, 'random', true);
Hasan canar
le 12 Fév 2021
Modifié(e) : Hasan canar
le 12 Fév 2021
Walter Roberson
le 12 Fév 2021
Notice that they are 0 and not nan, which is the value my code fills in when nothing is found. That implies that vpasolve thought 0 was close enough to a solution.
You might want to adjust the vpasolve options that deal with tolerance.
Hasan canar
le 12 Fév 2021
Modifié(e) : Hasan canar
le 12 Fév 2021
Walter Roberson
le 12 Fév 2021
Hmmm, there are no controls for precision for vpasolve... I thought there were.
You could try increasing digits()
Hasan canar
le 12 Fév 2021
Walter Roberson
le 13 Fév 2021
I would need your input file and your response to the input() questions to test more.
Hasan canar
le 13 Fév 2021
Walter Roberson
le 19 Fév 2021
My tests with Vg = -15 and those constants suggest that there is no zero for that function, including there not being any complex value that leads to a zero of the function.
Hasan canar
le 19 Fév 2021
Walter Roberson
le 19 Fév 2021
Perhaps, but the first Vg in Vg.txt is -15, and for Vg == -15, and the constants from your other const.txt my tests show there is no solution for Vs, including no complex solution.
Hasan canar
le 19 Fév 2021
Modifié(e) : Hasan canar
le 19 Fév 2021
Walter Roberson
le 19 Fév 2021
Q = @(v) sym(v);
syms Vs Vg p k d Vfb
load b1mhz.txt
Vg = b1mhz(:,1);
%{
prompt = 'k(dielectric constant) :';
k = Q(input(prompt));
prompt = 'p(doping const.) :';
p = Q(input(prompt));
prompt = 'd(thickness in cm) :';
d = Q(input(prompt));
prompt = 'Vfb(V) :';
Vfb = Q(input(prompt));
%}
d = 95e-7;
p = 5.095e16;
k = 3.73;
Vfb = -6.14;
numVg = length(Vg);
Sol = zeros(numVg,2,'sym');
wb = waitbar(0,'Please wait');
%onCleanup(@() delete(wb));
for i = 1:numVg
waitbar(i/numVg, wb);
Vgi = sym(sprintf('%g',Vg(i))); %we were seeing some odd floating point conversions
Sol(i,1) = Vgi;
eqn = Vgi - Vfb - Vs - (Q(11.7)/k)*((2*Q(0.026)*p*Q(1.6)*10^-19)/(Q(11.7)*Q(8.85)*10^-14))^Q(0.5)*(d*Q(11.7)/k)*(exp(-Vs/Q(0.026))+(Vs/Q(0.026))-1+(Q(1.5)*10^10/p)^2*(exp(Vs/Q(0.026))-(Vs/Q(0.026))-1))^Q(0.5);
thissol = vpasolve(eqn,Vs);
if isempty(thissol)
Sol(i,2) = nan;
else
Sol(i,2) = vpa(thissol,5);
guess = thissol;
end
Sol(i,:)
end
delete(wb)
disp(Sol)
Hasan canar
le 19 Fév 2021
Hasan canar
le 20 Fév 2021
Modifié(e) : Hasan canar
le 20 Fév 2021
For the Vg(-6.14 to +10 or so on) I should have got positive Vs values
Let us investigate:
d = 95e-7;
p = 5.095e16;
k = 3.73;
Vfb = -6.14;
syms Vg Vs
i = 1;
eqn = Vg(i) - Vfb - Vs - ((11.7)/k)*((2*(0.026)*p*(1.6)*10^-19)/((11.7)*(8.85)*10^-14))^(0.5)*(d*(11.7)/k)*(exp(-Vs/(0.026))+(Vs/(0.026))-1+((1.5)*10^10/p)^2*(exp(Vs/(0.026))-(Vs/(0.026))-1))^(0.5)
What sort of value would Vg(i) have to be in order for Vs = 1/1000 to be the solution?
Vg1000 = vpasolve(subs(eqn, Vs, 1/1000), Vg, -6)
vpasolve(subs(eqn, Vg, Vg1000), Vs)
Oh dear, we did not get back the same 1/1000 . Perhaps we need to hint?
vpasolve(subs(eqn, Vg, Vg1000), Vs, 1/72)
vpasolve(subs(eqn, Vg, Vg1000), Vs, 1/73)
So you can get the positive solution... but you have to start pretty close to the solution.
Is the negative value wrong?
eqn2 = subs(eqn, Vg, 0);
fplot(eqn2, [-0.14, 0.9])
No, we can see that although the function is not symmetric, that except for the peak, for every y value there are two x (Vs) values that give that result.
The y axes here is the negative of the Vg: so for Vg = 10, then when you add the negative 10 you get for Vs about -0.11, you would get 0; so Vg = 10, Vs about -0.11 is a solution to the equation. But also for Vg = 10, the negative 10 you get for Vs about 0.85 would give you a total of 0, so Vg = 10, Vs roughly 0.85 is also a solution.
Likewise, reading the part above the 0, we see that there are two solutions for each Vg in the range 0 to -6.14 .
And... this also means that there are no real-valued solutions for Vg < -6.14 .
For the range Vg (-15 to -6.14) I shoul have seen negative Vs values
No, graph the function and you will see that you cannot get those.
Vgsol = solve(eqn, Vg);
fplot(Vgsol, [-0.14, 0.9]); xlabel('Vs'); ylabel('Vg')
If you seem to find you get a solution with taylor expansion, then it could only be due to the limitations of taylor expansion in dealing with infinite functions.
I recommend that you go back and triple-check the equations and the constants being used.
Hasan canar
le 20 Fév 2021
No, I made it clear that Vg < -6.14 has no real solutions.
d = 95e-7;
p = 5.095e16;
k = 3.73;
Vfb = -6.14;
syms Vg Vs
i = 1;
eqn = Vg(i) - Vfb - Vs - ((11.7)/k)*((2*(0.026)*p*(1.6)*10^-19)/((11.7)*(8.85)*10^-14))^(0.5)*(d*(11.7)/k)*(exp(-Vs/(0.026))+(Vs/(0.026))-1+((1.5)*10^10/p)^2*(exp(Vs/(0.026))-(Vs/(0.026))-1))^(0.5)
Vgsol = solve(eqn, Vg);
VS = linspace(-0.14, 0.9, 500);
VG = double(subs(Vgsol, Vs, VS));
plot(VG, VS);
xlabel('Vg');
ylabel('VS')
[minvg, minidx] = min(VG);
fprintf('Minimum Vg was %g at Vs = %g\n', minvg, VS(minidx));
(Not exactly -6.14 because of the limitations of linspace for that many points.)
Your function has a exp(A*Vs) and an exp(-A*Vs) and a linear term and a constant. With that linear term, you could hope that it might cross zero twice, but that does not happen: it happens to balance out exactly at 0. And if you move away from zero in a positive direction, the exp(A*Vs) gets large quickly, and if you move away from zero in a negative direction, the exp(-A*Vs) gets large quickly. So.. there is just no possibility of extending further back than -6.14
Hasan canar
le 21 Fév 2021
Walter Roberson
le 21 Fév 2021
Look at the output of eqn in https://www.mathworks.com/matlabcentral/answers/739187-eqn-solver-could-not-solve-my-specific-seqn#comment_1342594
Look inside the sqrt and observe that you have a constant times Vs, and then you have exp(-500/26*Vs) and those terms are added together. The result cannot be symmetric around 0 because the constant times Vs contributes negative for negative Vs and contributes positive for positive Vs.
As you have now triple checked the equations, we are left with the conclusion that the paper is incorrect and needs to be withdrawn. Would you prefer to write your refutation to the journal, or to the authors directly, or would you prefer to have me send a formal refutation to the authors of the paper, citing your important role in bringing the flaw to attention?
Hasan canar
le 21 Fév 2021
0 votes
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





