Solution for system of two non linear equation
조회 수: 1 (최근 30일)
표시 이전 댓글
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
채택된 답변
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
2020년 5월 24일
편집: 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
2020년 5월 24일
댓글 수: 3
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!
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!