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"

1 回表示 (過去 30 日間)
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

採用された回答

Alan Weiss
Alan Weiss 2019 年 2 月 13 日
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
  1 件のコメント
J Vard
J Vard 2019 年 2 月 13 日
Thanks for your comment.
The guess value I have given, i.e x0 = [0.001 1.0] is the reason.
At x0 = 1.0 the limit goes to infinity (P*y1/(1-x1)).
When is adjust it to less than 1.0, i.e 0.999, then I get no warnings, but the results are the same, however.
Thank you,
Question closed.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by