Function 'fzero' display "Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.8e+01. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy"
4 views (last 30 days)
Show older comments
Hi all,
I have written the following code. I have used 'fzero' function to find the root of a single non-linear equation (x1, here). When I execute the program, I get several warning messages as mentioned in the title. I have cross checked the values by subsituting them in the equation. They turn out to be correct.
My query is why is MATLAB showing these messages? Is there any thing wrong in my code? If so, what changes I have to make in order to rectify the warnings messgaes.?
Thanks in advance.
clear all
data=xlsread('file.xls');
P1 = data(:,1);
P2 = data(:,4);
Q1 = data(:,2);
Q2 = data(:,5);
fun_one=@(b1,P1) ((b1(2)*b1(1)*P1)./(1+(b1(1)*P1)));
fun_two=@(b2,P2) ((b2(2)*b2(1)*P2)./(1+(b2(1)*P2)));
b10=[0.1;12];b20=[1;1];
b1=lsqcurvefit(fun_one,b10,P1,Q1);
b2=lsqcurvefit(fun_two,b20,P2,Q2);
Q_H2S=((b1(2)*b1(1)*P1)./(1+(b1(1)*P1)));
Q_CO2=((b2(2)*b2(1)*P2)./(1+(b2(1)*P2)));
%%
P=[0.1 0.3 0.5 0.7 0.9 1.0 2.0 4.0 6.0 8.0 10.0]; % total pressure
l=length(P);
y1=0.50;x0=[0.001; 1.0];
y2=1-y1;
x1=zeros(l,1);
x2=zeros(l,1);
selectivity=zeros(l,1);
selc=zeros(l,1);
for i=1:l
x1(i)=fzero(@(x1) ((integral(@(P1) ((b1(2)*b1(1))./(1+(b1(1)*P1))),0,(P(i)*y1)/x1))-(integral(@(P1) ((b2(2)*b2(1))./(1+(b2(1)*P1))),0,(P(i)*y2)/(1-x1)))),x0);
x2(i)=1-x1(i);
selectivity(i) = (x1(i)./y1)/(x2(i)./y2);
selc(i) = 1./selectivity(i);
end
My P1, Q1, and P2, Q2 values are
P1 Q1 P2 Q2
0.1 0.4358 0.1 0.1812
0.3 1.1942 0.3 0.4962
0.5 1.6863 0.5 0.794
0.7 1.9956 0.7 1.0533
0.9 2.2067 0.9 1.291
1 2.2876 1 1.3929
2 2.7613 2 2.1686
4 3.2189 4 2.9792
6 3.5246 6 3.4219
8 3.771 8 3.7221
10 3.964 10 3.9461
0 Comments
Accepted Answer
Alan Weiss
on 13 Feb 2019
As the warning clearly states, this is not being issues from fzero, but is instead being issued from integral. You should figure out why the integration is having trouble; the problem is not with fzero.
Alan Weiss
MATLAB mathematical toolbox documentation
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!