Solution for system of two non linear equation

2 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Are Mjaavatten
Are Mjaavatten il 24 Mag 2020
Modificato: Are Mjaavatten il 24 Mag 2020
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 Commenti
Anil Kumar
Anil Kumar il 24 Mag 2020
Thanks sir !!
I will try this also.
Though I had tried the following code;
The problem is that fval is not converging to zero, at any range of X
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 200 (the default value).
X =
1.0e+03 *
-1.7478
4.2340
fval =
1.0e+20 *
0.3882
-6.7548
Kb=1.38*10^-23
T=700
Eact=0.15*1.6*10^-19
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))/(Ns*(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])
Are Mjaavatten
Are Mjaavatten il 24 Mag 2020
Modificato: Are Mjaavatten il 24 Mag 2020
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.

Accedi per commentare.

Più risposte (1)

Anil Kumar
Anil Kumar il 24 Mag 2020
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 Commenti
Alex Sha
Alex Sha il 24 Mag 2020
there are two set of solutionas:
1:
x1: -7.92007748296389E19
x2: 1866379606242.77
2:
x1: -7.92557459212419E19
x2: 6.70668919804731E19
Are Mjaavatten
Are Mjaavatten il 25 Mag 2020
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!

Accedi per commentare.

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by