Finding the number of values about nonlinear equations.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
지홍 윤
el 27 de Nov. de 2021
Comentada: 지홍 윤
el 27 de Nov. de 2021
I want to find the number of values about nonlinear equations.
I try to use 'fzero' but it could be calculated in only one value.
If there's a way to solve this problem, please let me know.
Thank you
Attached is the code below.
clear all
%%%%%%%%%%%%%%%%%%%%%%Declaration of variables%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Tn=800;
R=8.3146261815324;
H_1=11326.16;
Tm_1=1234.95;
H_2=13423;
Tm_2=1356.35;
as_1=34532;
bs_1=-9.178;
as_2=-5996;
bs_2=1.725;
syms dG_1 dG_2 T x dG_ex_l dG_ex_s dG_l(x,T) dG_s(x,T) x_ x_0 x_1 x_2
dG_1=H_1*((Tm_1-T)./Tm_1);
dG_2=H_2*((Tm_2-T)./Tm_2);
dG_ex_s=(1-x)*x*(as_1+bs_1*T)+(1-x)*x*(as_2+bs_2*T)*(1-2*x);
dG_s=-(1-x)*dG_1+R*T*((1-x)*log(1-x)+x*log(x))+dG_ex_s;
dG_s_const_T=subs(dG_s,[x, T], [x_, Tn]);
%fplot(dG_s_const_T,[0 1])
%%%%%%%%%%%%%%%%%%%%%%Declaration of variables%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Diff_dG_s_f1 = diff(dG_s_const_T,x_); %%%%%%%%%%%%%%% nonlinear equatiion %%%%%%%%%%%%%%
fplot(Diff_dG_s_f1,[0 1])
f=matlabFunction(Diff_dG_s_f1);
%[val1,val2,val3] = vpasolve(Diff_dG_s_f1,[0 1])
x_0= fzero(f,[0.00000000000001 0.99999999999999]);
0 comentarios
Respuesta aceptada
John D'Errico
el 27 de Nov. de 2021
Editada: John D'Errico
el 27 de Nov. de 2021
You need to understand it is IMPOSSIBLE to know the number of solutions to a general nonlinear equation, or system of them.
In this case, in the interval of interest, there appear to be 3 real roots. But singe the problem is nonlinear, fzero cannot find them all. See my first comment. Accept it as truth, and know that since fzero can only interrogate the function at a finite number of points, it cannot know how to find all roots in that interval.
A simple solution is to evaluate the cuntion at a finite set of points yourself. So if we have:
f=matlabFunction(Diff_dG_s_f1);
x = linspace(0.00000000000001,0.99999999999999,1000);
fx = f(x);
find(diff(sign(fx)))
ans =
20 698 981
So there are 3 spots identified where the function changes sign on that sampling.
idx = find(diff(sign(fx)))
idx =
20 698 981
and now we can find the three roots using fzero.
fzero(f,[x(idx(1)),x(idx(1) + 1)])
ans =
0.0196
fzero(f,[x(idx(2)),x(idx(2) + 1)])
ans =
0.6985
fzero(f,[x(idx(3)),x(idx(3) + 1)])
ans =
0.9811
Más respuestas (0)
Ver también
Categorías
Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!