equation solver solve()

Hi all,
I use eqn solver for solving non-linear equation. ı have an array with constants and for the value Vg = -5.24, soln must be Zero but I got an error:
Error using subsasgn
Subscripted assignment dimension mismatch.
Error in sym/privsubsasgn (line 997)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 834)
C = privsubsasgn(L,R,inds{:});
Error in onebytwo (line 25)
Sol(i) = vpasolve(Vs == Vg(i) + 5.24 - 1.8996*(exp(-Vs/0.026)+ Vs/0.026 -1 + 8.65*10^-14*(exp(Vs/0.026) - Vs/0.026 -1))^0.5, Vs,
guess)
Also below -5.24 ( -5.2,-5.0 ... etc) code works fine but does not solve Vg with more than two values. For this ı got an error like ;
Error using subsasgn
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in sym/privsubsasgn (line 997)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 834)
C = privsubsasgn(L,R,inds{:});
Error in onebytwo (line 22)
Sol(i) = vpasolve(Vs == Vg(i) + 5.24 - 1.8996*(exp(-Vs/0.026)+ Vs/0.026 -1 + 8.65*10^-14*(exp(Vs/0.026) - Vs/0.026 -1))^0.5, Vs,
guess)
Moreover, Code does not solve values of Vg above -5.24 (-5.4,-5.6 ... etc)
Here is my code.
clear all
syms Vs Vg
guess = 0.01;
Vg = [
-5.4
-5.24
-5.2
-5.0
-4.8
-4.6
-4.4
];
for i = 1:length(Vg)
Sol(i) = vpasolve(Vs == Vg(i) + 5.24 - 1.8996*(exp(-Vs/0.026)+ Vs/0.026 -1 + 8.65*10^-14*(exp(Vs/0.026) - Vs/0.026 -1))^0.5, Vs, guess)
if ~isempty(Sol); guess = Sol; end
end
Hope I can get help.
Thank you
Hasan

Answers (1)

Walter Roberson
Walter Roberson on 14 Feb 2021
Edited: Walter Roberson on 14 Feb 2021

0 votes

I clearly showed in https://www.mathworks.com/matlabcentral/answers/739187-eqn-solver-could-not-solve-my-specific-seqn#comment_1322742 how to deal with that problem of subscript mismatch, with the thissol approach and testing for empty before assigning into the array.

12 Comments

@Walter Roberson It does not solve it Vg with less than -5.24 (-5.4 , -5.6 etc)
So? This question is about subscript mismatches, and I already showed you how to solve that problem, days ago.
Hasan canar
Hasan canar on 14 Feb 2021
Edited: Hasan canar on 14 Feb 2021
Error using subsasgn
In an assignment A(:) = B, the number of elements in A and B must be the same.
Hasan canar
Hasan canar on 14 Feb 2021
Edited: Hasan canar on 14 Feb 2021
@Walter Roberson actually the code above solves for array values higher than -5.24 but gives error for less than -5.24. Maybe it finds complex number ? Is it so? I cannot explain '' error with Dimension mismatch '' in other way
Sol(i) = vpasolve(Vs == Vg(i) + 5.24 - 1.8996*(exp(-Vs/0.026)+ Vs/0.026 -1 + 8.65*10^-14*(exp(Vs/0.026) - Vs/0.026 -1))^0.5, Vs, guess)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Extract the underlined part:
- 1.8996*(exp(-Vs/0.026)+ Vs/0.026 -1 + 8.65*10^-14*(exp(Vs/0.026) - Vs/0.026 -1))^0.5
What does that look like? Well, if you draw it close to 0, you will see that lt looks like it has a pointy local maxima of -4/25 at Vs = 0. Does that check with calculus? Take the derivative and plot it near zero and you will see a discontinuity for sure at 0, with the derivative being about +50 for negative Vs and about -50 for positive Vs. If you break up the derivative further there is a part that is a division by 0 at Vs = 0
So.. the maximum value of that big sub-expression is -4/25.
Now look at the expresson before that:
Vs == Vg(i) + 5.24 + (something that is at most -4/25)
and let Vg(i) be -5.24 . Then that -5.24 Vg(i) balances the 5.24 and gives you
Vs == 0 + (something that is at most -4/25)
That hints maybe Vs could be -4/25, but the -4/25 was when Vs = 0, and near Vs = -4/25 the term is closer to -40
Effectively in order to find a zero, you have to count on the Vg(i) + 5.24 being positive to balance out the negative of the longer expression, and that cannot happen when Vg(i) < -5.24 (or at -5.24 either.)
So... unless you are willing to accept complex-valued solutions, you are not going to get any further, except perhaps to pin down the exact boundary slightly greater than -5.24.
In earlier discussion, you said that the solutions should be real-valued, so I will not bother investigating the families of complex-valued solutions .
At this point I would suggest you have another look at how the 5.24 got into your original formula.
@Walter Roberson Thank you for turn back. It is well clear from your statement that -4/25 = -0.16 is the max. value that Vs takes in the reverse direction. In positive part, it ~ 0.86.
What I am trying to do is calculating the surface potential for the Silicon crysal and its Energy band gap is 1.12 eV. So, 0.16+ 0.86 makes sense. but I have to fill the unknown part which is -0.16 to 0. Actually, I m interested in real solutions but we know that imaginary numbers also have real parts. Probably , finding complex solutions for that unknown part can tell us something.
Now, I have to modify the code for complex solutions.
You can modify the initial guess further. Just do not use 0 as the imaginary component for the initial guess, or else vpasolve() will not look for imaginary solutions.
syms VsR VsI real
Vg = [
-5.4
-5.24
-5.2
-5.0
-4.8
-4.6
-4.4
];
Q = @(v) sym(v);
numVg = length(Vg);
Sol = zeros(numVg, 3, 'sym');
Vs = VsR + 1i*VsI;
guess = [-0.01; -2];
for i = 1:length(Vg)
eqn = Vs == Vg(i) + Q(5.24) - Q(1.8996)*(exp(-Vs/Q(0.026))+ Vs/Q(0.026) -1 + Q(8.65)*10^-14*(exp(Vs/Q(0.026)) - Vs/Q(0.026) -1))^Q(0.5);
eqn_sep = [real(lhs(eqn))==real(rhs(eqn)), imag(lhs(eqn)) == imag(rhs(eqn))];
thissol = vpasolve(eqn_sep, [VsR, VsI], guess);
if isempty(thissol) || isempty(thissol.VsR)
Sol(i,:) = [sym(Vg(i),'d'), nan, nan];
else
thissolsep = [thissol.VsR, thissol.VsI];
Sol(i,:) = [sym(Vg(i),'d'), thissolsep];
guess = thissolsep;
end
end
Sol
Sol = 
Thank you Mr. @Walter Roberson . I really appreciate your support. I am a bit dissapointed that I could not find negative values for Vs.
Hasan canar
Hasan canar on 16 Feb 2021
Edited: Hasan canar on 16 Feb 2021
@Walter Roberson As I stated earlier, Silicon band gap is 1.12eV I got 0.86 of it and for the remaining part I will generate data in a specific range like -0.16 to 0 with certain amount that is equal to the remaining data points . Not the best option but there is no any other option too
syms VsR VsI real
Vg = [
-5.4
-5.35
-5.3
-5.25
-5.24
-5.2
-5.0
-4.8
-4.6
-4.4
];
Q = @(v) sym(v);
numVg = length(Vg);
Sol = zeros(numVg, 3, 'sym');
Vs = VsR + 1i*VsI;
guess = [-0.01; -20];
for i = 1:length(Vg)
eqn = Vs == Vg(i) + Q(5.24) - Q(1.8996)*(exp(-Vs/Q(0.026))+ Vs/Q(0.026) -1 + Q(8.65)*10^-14*(exp(Vs/Q(0.026)) - Vs/Q(0.026) -1))^Q(0.5);
eqn_sep = [real(lhs(eqn))==real(rhs(eqn)), imag(lhs(eqn)) == imag(rhs(eqn))];
thissol = vpasolve(eqn_sep, [VsR, VsI], guess);
if isempty(thissol) || isempty(thissol.VsR)
Sol(i,:) = [sym(Vg(i),'d'), nan, nan];
else
thissolsep = [thissol.VsR, thissol.VsI];
Sol(i,:) = [sym(Vg(i),'d'), thissolsep];
guess = thissolsep;
end
end
vpa(Sol,16)
ans = 
Hasan canar
Hasan canar on 16 Feb 2021
Edited: Hasan canar on 16 Feb 2021
@Walter Roberson I got an error with that code (I m using R2015a)
Undefined function 'lhs' for input arguments of type 'sym'.
Error in WalterRoberson (line 22)
eqn_sep = [real(lhs(eqn))==real(rhs(eqn)), imag(lhs(eqn)) == imag(rhs(eqn))];
I put 'lhs' to syms and got another one
Error using syms (line 97)
Not a valid variable name.
Error in WalterRoberson (line 1)
syms VsR VsI real 1hs
Hasan canar
Hasan canar on 16 Feb 2021
Edited: Hasan canar on 16 Feb 2021
@Walter RobersonI need to find such a graph from that equation[1].
When Vg = 5.24 Vs has to be 0 ! This is strict and if not holds physics behind the problem will be devastated.
Also, negative values exist for the same equation with different numbers (Vg, 1.8996, etc are different) but it does not change the situation.
Also, up to now you may find what I got so far, obviously w/out negative Vs values;
It can be easily claimed that I have a same trend as the literature and my data stucks at Vg = -5.24.
[1] Novkovski, 2017.

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 14 Feb 2021

Edited:

on 16 Feb 2021

Community Treasure Hunt

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

Start Hunting!