Optimaloptions doesn't seem to work

1 回表示 (過去 30 日間)
Yu Ting
Yu Ting 2024 年 3 月 26 日
コメント済み: Yu Ting 2024 年 3 月 26 日
I was trying to solve a system of 9 non-linear equations using fsolve. However, I ran into a problem that quite unexpected.
After running the code, on the command screen it wrote:
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 9.000000e+02.
Therefore, I added the optimaloptions command trying to increase the MaxFunctionEvaluations :
options = optimoptions(@fsolve,'MaxFunctionEvaluations',10000);
x= fsolve(f,[0.01,0.01,0.01,0.01,0.9,0.1,0.1,0.1,10000]);
However, the calculation results didn't change at all, on the command screen it wrote again:
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 9.000000e+02.
I also could't change functiontolerance, optimalitytolerance, steptolerance, etc.
Is there an issue in my code? Or is it other issue?
Thanks for helping.
The full code is below (I trimmed out the parameters input to save space).
%%%%%%%%%%%%%% Solving the systems of equations for IAST model %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% calculate initial C for all
PCE_ini= PCE_sim +(ma)./(Vw+Vg.*H_PCE./R./T).*KF_PCE_TOG.*PCE_sim.^N_PCE_TOG;
TCE_ini= TCE_sim +(ma)./(Vw+Vg.*H_TCE./R./T).*KF_TCE_TOG.*TCE_sim.^N_TCE_TOG;
cDCE_ini= cDCE_sim +(ma)./(Vw+Vg.*H_cDCE./R./T).*KF_DCE_TOG.*cDCE_sim.^N_DCE_TOG;
tDCE_ini= tDCE_sim +(ma)./(Vw+Vg.*H_tDCE./R./T).*KF_DCE_TOG.*tDCE_sim.^N_DCE_TOG;
f=@(x)[
x(1)-(x(9).*N_PCE_TOG./KF_PCE_TOG).^(1./N_PCE_TOG).*x(5);
x(2)-(x(9).*N_TCE_TOG./KF_TCE_TOG).^(1./N_TCE_TOG).*x(6);
x(3)-(x(9).*N_DCE_TOG./KF_DCE_TOG).^(1./N_DCE_TOG).*x(7);
x(4)-(x(9).*N_DCE_TOG./KF_DCE_TOG).^(1./N_DCE_TOG).*x(8);
(Vw+Vg.*H_PCE./R./T)./ma.*(PCE_ini-x(1))-x(5).*( (x(5)./(KF_PCE_TOG.*x(1).^N_PCE_TOG))+(x(6)./(KF_TCE_TOG.*x(2).^N_TCE_TOG))+(x(7)./(KF_DCE_TOG.*x(3).^N_DCE_TOG))+(x(8)./(KF_DCE_TOG.*x(4).^N_DCE_TOG))).^(-1);
(Vw+Vg.*H_TCE./R./T)./ma.*(TCE_ini-x(2))-x(6).*( (x(5)./(KF_PCE_TOG.*x(1).^N_PCE_TOG))+(x(6)./(KF_TCE_TOG.*x(2).^N_TCE_TOG))+(x(7)./(KF_DCE_TOG.*x(3).^N_DCE_TOG))+(x(8)./(KF_DCE_TOG.*x(4).^N_DCE_TOG))).^(-1);
(Vw+Vg.*H_cDCE./R./T)./ma.*(cDCE_ini-x(3))-x(7).*( (x(5)./(KF_PCE_TOG.*x(1).^N_PCE_TOG))+(x(6)./(KF_TCE_TOG.*x(2).^N_TCE_TOG))+(x(7)./(KF_DCE_TOG.*x(3).^N_DCE_TOG))+(x(8)./(KF_DCE_TOG.*x(4).^N_DCE_TOG))).^(-1);
(Vw+Vg.*H_tDCE./R./T)./ma.*(tDCE_ini-x(4))-x(8).*( (x(5)./(KF_PCE_TOG.*x(1).^N_PCE_TOG))+(x(6)./(KF_TCE_TOG.*x(2).^N_TCE_TOG))+(x(7)./(KF_DCE_TOG.*x(3).^N_DCE_TOG))+(x(8)./(KF_DCE_TOG.*x(4).^N_DCE_TOG))).^(-1);
x(5)+x(6)+x(7)+x(8)-1]
options = optimoptions(@fsolve,'MaxFunctionEvaluations',10000);
x= fsolve(f,[0.01,0.01,0.01,0.01,0.9,0.1,0.1,0.1,10000]);
PCE_eq=x(1);
TCE_eq=x(2);
cDCE_eq=x(3);
tDCE_eq=x(4);
Z_PCE=x(5);
Z_TCE=x(6);
Z_cDCE=x(7);
Z_tDCE=x(8);
Phi=x(9);
fprintf('PCE_eq = %d\n',PCE_eq)
fprintf('TCE_eq = %d\n',TCE_eq)
fprintf('cDCE_eq = %d\n',cDCE_eq)
fprintf('tDCE_eq = %d\n',tDCE_eq)
fprintf('Z_PCE = %d\n',Z_PCE)
fprintf('Z_TCE = %d\n',Z_TCE)
fprintf('Z_cDCE = %d\n',Z_cDCE)
fprintf('Z_tDCE = %d\n',Z_tDCE)
fprintf('Phi = %d\n',Phi)

採用された回答

Torsten
Torsten 2024 年 3 月 26 日
編集済み: Torsten 2024 年 3 月 26 日
You didn't include the "options" setting in the call to "fsolve":
x= fsolve(f,[0.01,0.01,0.01,0.01,0.9,0.1,0.1,0.1,10000],options);
instead of
x= fsolve(f,[0.01,0.01,0.01,0.01,0.9,0.1,0.1,0.1,10000]);
  1 件のコメント
Yu Ting
Yu Ting 2024 年 3 月 26 日
Oh snap!
Thanks a lot!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by