Solution for system of two non linear equation
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Anil Kumar
le 24 Mai 2020
Commenté : Are Mjaavatten
le 25 Mai 2020
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)
0 commentaires
Réponse acceptée
Are Mjaavatten
le 24 Mai 2020
Modifié(e) : Are Mjaavatten
le 24 Mai 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 commentaires
Are Mjaavatten
le 24 Mai 2020
Modifié(e) : Are Mjaavatten
le 24 Mai 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.
Plus de réponses (1)
Anil Kumar
le 24 Mai 2020
3 commentaires
Alex Sha
le 24 Mai 2020
there are two set of solutionas:
1:
x1: -7.92007748296389E19
x2: 1866379606242.77
2:
x1: -7.92557459212419E19
x2: 6.70668919804731E19
Are Mjaavatten
le 25 Mai 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!
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!