Finding the number of values about nonlinear equations.

1 view (last 30 days)
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]);

Accepted Answer

John D'Errico
John D'Errico on 27 Nov 2021
Edited: John D'Errico on 27 Nov 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
  1 Comment
지홍 윤
지홍 윤 on 27 Nov 2021
Thank you for the information. I'm able to learn a lot. I will use a method of calculating by dividing the tiny section

Sign in to comment.

More Answers (0)

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!