fmincon question - does not converge to useful answer
Show older comments
Ok, so I am trying to write a program that can calculate the critical temperature and critical volume of a mixture of n components. This program is going to be part of a larger program that I am writing to do thermodynamic calculations.
This is how it works (or will work hopefully): The user inputs the required data on the components (critical temperature, critical pressure, mole fraction, and the component names). The program uses this data to minimize the Helmholtz free energy, thus calculating the critical point of the mixture. Basically, there are n+2 equations that equal zero to solve simultaneously (n number of PDE's for fugacity, 1 for the second PDE of the fugacity, and one constraining the perturbation vector to be always non-zero. I wrote a function that should do this, but I'm getting erroneous results. For the problem below, the critical temperature should be 462.64 K, the critical volume should be 228.83 cc/gmol, and the critical pressure should be 117 bar. The perturbation components should be 0.1137, 0.0485, and -0.9923, respectively. I'm having issues with getting fmincon converging to the right answer. If anyone can take a look at the code below and comment me, and my head that has been banging off the wall for two weeks would appreciate it.
The code that I wrote below only seems to vary the perturbation variables "del_n". It often returns the initial guesses for temperature and volume as the final answers. Is this the right way to approach this problem?
8 Comments
Sean de Wolski
on 21 Feb 2013
What does the iter-detailed output look like?
Joshua
on 21 Feb 2013
Joshua
on 23 Feb 2013
Joshua
on 23 Feb 2013
Joshua
on 23 Feb 2013
Changxu
on 6 Sep 2023
Moved: Bruno Luong
on 6 Sep 2023
Hi, are you still there? I want to know the Tc, Pc and Vc calculated by PR EOS. Then know the deviation between critical properties obtained by PR EoS and the experimental data.
How can I achieve this? I don't know how to use Helmholtz energy calculationto realize it. And for now, I know how to calculate the saturated properties by using PR EoS.
Can you help me? Thanks.
Answers (2)
I don't think you've showed us your objective function. In your call to fmincon, you designate the objective function as '1'
fmincon('1',g0,[],[],[],[],lb,ub,@crit_param,options)
which should not work.
Aside from this, I'll point out that you have sqrt() operations all over the place. That will make the function non-differentiable at zero and undefined below 0, unless you're sure the quantites being sqrt-ed stay well above zero due to imposed bounds. Even with imposed bounds, you would probably need to make sure your bounds are always honored using the 'AlwaysHonorConstraints' option which is only available in certain methods (interior-point and sqp, I think).
If you know what the solution should be, initialize FMINCON at that solution and see if FMINCON gives that solution back to you as its output. If it does, your original problem may have been a local minimum and you need to initialize better. If it does not, the solution you're expecting is just not a minimum of the function as you've provided it to fmincon. You may have an error translating your physics into code... a problem only you're equipped to address.
2 Comments
Joshua
on 21 Feb 2013
Matt J
on 21 Feb 2013
Forget about FMINCON then. Just concentrate on debugging your objective function. Plug in the unknown solution and run the objective function in the debugger. Step through line by line until you reach a line that doesn't give the expected result.
Categories
Find more on Structural Mechanics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!