fmincon nonlinear constraints not being optimized

2 views (last 30 days)
Im working on modeling battery gassing. I have IR absorption data from research papers. I know the ratios of these absorption intensities are proportional to the ratios of the number of moles of component gases and thus the average parasitic currents for each component. When i try to optimize my chemical reaction equations to the absorption data my nonlinear constraints do not change. My non linear constraints are of the form:
ceq3=totalcurrent/totalcurrent313K-0.265873214;
ceq4=totalcurrent/totalcurrent333K-0.06471225;
but the final values are just the constants ie ceq3=-0.26 and ceq4=-0.065
How do i get the solver to do this better? I have tried messing with the contraint tolerances and function tolerance.

Answers (1)

Alan Weiss
Alan Weiss on 22 Feb 2021
Edited: Alan Weiss on 22 Feb 2021
Your code contains a lot of lines of the form
averagecurrentH2(isnan(averagecurrentH2))=0;
When I run your entire code in debugging mode I see that many of these lines are active; in other words, many of the calculations are returning NaN and then returning 0. I suspect that you don't really want all these NaN values, and that something is going wrong with your calculation, and that is why fmincon gets stuck.
FYI, I set a 0 objective function
fun = @(x)0;
I suggest that you debug your nonlinear constraint function. And also, when that is debugged, set your objective to the square of the difference, not the absolute value of the difference:
error = norm((averagecurrentCO2+averagecurrentCO+averagecurrentC2H4+averagecurrentC2H6+averagecurrentO2+averagecurrentPOF3+averagecurrentH2) - 1e-3)^2;
% not
error=abs((averagecurrentCO2+averagecurrentCO+averagecurrentC2H4+averagecurrentC2H6+averagecurrentO2+averagecurrentPOF3+averagecurrentH2)-1*10^-3);
Alan Weiss
MATLAB mathematical toolbox documentation
  1 Comment
Anosh Mevawalla
Anosh Mevawalla on 24 Feb 2021
i did that and is not having any effect my ceq is still converging to
ceq =
-0.0000
0.0000
-0.2659
-0.0647
for some reason it is not considering the constant term subtracted.

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!