MATLAB Answers

Solution for system of two non linear equation

2 ビュー (過去 30 日間)
Anil Kumar
Anil Kumar 2020 年 5 月 24 日
コメント済み: Are Mjaavatten 2020 年 5 月 25 日
Hello everyone! I want to solve the following set of equations for Ns and Nonegative
other parameters like Nd, kb,T,Ed and E0 are given. please guide me
B*((Nd-Ns-Nonegative)/(Ns*(Ns+Nonegative)))=exp(Ed/(kb*T)) ..........................(1)
(Nd-Ns-Nonegative)*(No-Nonegative)/(Nonegative*(Ns-Nonegative))=exp((Ed-E0)/(kb*T)).....................(2)

採用された回答

Are Mjaavatten
Are Mjaavatten 2020 年 5 月 24 日
編集済み: Are Mjaavatten 2020 年 5 月 24 日
You can rewrite you equations as
(Nd-x-y)-a*(x*(x+y)) = 0
(Nd-x-y)*(No-y)-b*(y*(x-y)) = 0
where x = Nd, y = Nonegative, a = exp(Ed/(kb*T))/B, b = exp((Ed-E0)/(kb*T)).
Now you may create the function
function residual = kumar_fun(z,Nd,No,a,b)
x = z(1);
y = z(2);
residual(1,1) = (Nd-x-y)-a*(x*(x+y));
residual(2,1) = (Nd-x-y)*(No-y)-b*(y*(x-y));
end
Function fsolve from the optimization toolbox will try to find an x and y pair that gives zero residuals. Use an inline function to transfer the parameters:
fun = @(z) kumar_fun(z,Nd,No,a,b);
z0 = [1;1]; % You may have to try other initial values
z = fsolve(fun,[1;1]);
Ns = z(1);
Nonegative = z(2);
If you do not have the optimization toolbox you may try my broyden, or you may search the File Exchange for "nonlinear equation solver". Note that, depending on your parameters, there is a chance that your equation system has more than one solution or no solution at all.
  2 件のコメント
Are Mjaavatten
Are Mjaavatten 2020 年 5 月 24 日
There is an error in your expression for f. In position 29 you should use X(1) instead of Ns, since Ns will not change during the solution procedure. If you still find no solution I could give it a try myself. I need values for B and No. Note that Eact is not used.

サインインしてコメントする。

その他の回答 (1 件)

Anil Kumar
Anil Kumar 2020 年 5 月 24 日
Thank you for your kind support sir, but even after your suggestion value of fval not converging to zero for the accurate solution of Nonegative and Ns...It will be kind help if you could try it! Thanks in anticipation!
Kb=1.38*10^-23
T=700
B= 8.5896e+24
No= 1.7108e+12
E0= 0.85*1.6*10^-19
Nd= 10^16
Ed= 0.7*1.6*10^-19
X1=Ns
X2= Nonegative
f=@(X)[B*((Nd-X(1)-X(2))/(X(1)*(X(1)+X(2))))-(exp(Ed/(Kb*T)));((Nd-X(1)-X(2))*(No-X(2))/(X(2)*(X(1)-X(2))))-(exp((Ed-E0)/(Kb*T)))]
fsolve (f,[0 1])
[X, fval]=fsolve (f,[0 1])
  3 件のコメント
Are Mjaavatten
Are Mjaavatten 2020 年 5 月 25 日
The problem is that your function varies so fast it cannot be calculated accurately enough using Matlab's doubles, which can only give around 15 decimals accuracy. Example: By increasing the input by the smallest amout possible, the function value varies by 3*10^25!:
>> X0 = [1,1];X1 = X + [eps,0];
>> f0 = B*((Nd-X0(1)-X0(2))/(Ns*(X0(1)+X0(2))))-(exp(Ed/(Kb*T)));
>> f1 = B*((Nd-X1(1)-X1(2))/(Ns*(X1(1)+X1(2))))-(exp(Ed/(Kb*T)));
>> f0-f1
ans =
2.901421967075110e+25
In order to solve this you will need to use high-precisison numerics. I believe this is possible using the symbolic toolbox, which I do not have. I did manage to solve your problem using the 'decimal' package in Python. Using 70 digits precision (which was probably an overkill) I got the results:
x = 4995902546762269.237720253171526889970117329871362498338512315098994153
y = 5003466623785482.322209836772145823825707627909875825586084623755567318
If you put this into Matlab, the values will get rounded to 15 digits and the second equation will not yield 0 but -2.84e15!
I recommend that you take another look at your equations and parameters to see if they are correct or if they may be reformulated.
I did have some nerdy fun figuring this out though!

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by