cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Highlighted

Minerr/nonlinear optimizing

In reference to this document: Minerr/nonlinear optimizing

Your equation for Function is wrong. For a least squares fit the error function should be the square root of the sum of the squares (or just the sum of the squares). You have the sum of the square root of the squares, which is equivalent to the sum of the absolute values. See my Function2 for the correct error function.

Having said that, the best way to fit a function to experimental data is to create a function that generates the vector of residuals: see my Function3. Feed that directly to minerr, and use the Levenberg-Marquardt option.

Minimizing Function gives an error (i.e. Function2) of 1721, 311, or 133, depending on the algorithm used

Minimizing Function2 gives an error (i.e. Function2) of 1628, 109, or 100, depending on the algorithm used

Minimizing Function3 using the LM algorithm gives an error (i.e. Function2) of 261

I'm not sure why the last option does not give an error as low as a couple of the other options, except to say it has to do with where the minimization ends. Using a vector of residuals with the LM algorithm, maybe it takes a slightly different path and gets trapped somewhere in a local minimum. Changing the guesses may help. Nevertheless, despite the fact that the error is slightly higher in this example, in general this is the best approach.

22 REPLIES 22

Re: Minerr/nonlinear optimizing

I played around a little, and it's super sensitive to the guess values. I'm not sure anything we have found is the true minimum, and I'm not sure any gradient method is the way to find the true minimum. Maybe simulated annelaing: Minimizing a Function using Simulated Annealing. I'm traveling in Europe at the moment though, so I'm not sure when I will find time to try that.

Re: Minerr/nonlinear optimizing

I would like to joint the discussion about Minerr Levenberg-Marquardt, since  I found me to some convergence issue, for some additional points:

1) It is possible to use relative deviations( |X-Xxep|/Xexp instead of residual ( |X-Xexp| (  in order to taking in account the variable absolute value) (?)

2)  It is possible to consider two ( or more)  weighted objective functions to be minimized in the same solve block or it is best to consider the sum of them ( a single boolean equation) (?)

3)  In order to check wheter Minerr has found a true minimum, it is possible to use the ERR function  alternatively to recalculate the objective function?

Re: Minerr/nonlinear optimizing

 1) It is possible to use relative deviations( |X-Xxep|/Xexp instead of residual ( |X-Xexp| (  in order to taking in account the variable absolute value) (?)

Yes, it is just a weighted fit. For a true least squares fit the errors should all be of equal standard deviation. If the errors are independent of the magnitude of the data that means they should be unweighted. If the errors are proportional to the magnitude of the data then they should be weighted by 1/magnitude, which is what you propose.

 2)  It is possible to consider two ( or more)  weighted objective functions to be minimized in the same solve block or it is best to consider the sum of them ( a single boolean equation) (?)

Yes, just stack the (weighted) residuals, or put them in two columns of a matrix.

 3)  In order to check wheter Minerr has found a true minimum, it is possible to use the ERR function  alternatively to recalculate the objective function?

I'm not sure what you mean. The ERR function is a built-in variable, not a function, that gives you the error in the fit. When minerr stops iterating it has found either a flat area in the objective function or a minimum. There is no way to know which (other than by trying different guesses), and no way to know if it is the global minimum.

Re: Minerr/nonlinear optimizing

Thank you,

I am currently applying the Minerr Levenberg-Marquardt for the classical chemical engineering problem of fitting the pure component parameters of a volumetric EOS ( Equation of State ) versus experimental vapour pressure and liquid density. Since the equation is implicit on the density, depending on the initial values, Minerr could converge to a false minimum ( e.g. wrong root: vapor density). Could  the minimization problem be solved alternatively with Simplex algorithm type. Is this available in MathCAD?

Re: Minerr/nonlinear optimizing

Hi.

Not with Minerr.

With minimize, you can impose the adequate conditions inside the solve block with <, <= to the variables to ensure the convergence to the desired range. But then the problem is how to express the zero of the function. For a lot of problems works simply include abs(f(x,y,..))=0 or something about squares and related conditions. But for several variables it could be problematic.

With solve you can also include restriction over the variable domain, and don't need to prepare the function to solve too much. But, again, for several variables don't works for the general case, and need to use minimize with an optimized condition for f.

As comment, can't read the water data, mathcad says something about loss region when load the worksheet. But don't know if it is my problem, or others collabs have it.

Best regards.

Alvaro.

Re: Minerr/nonlinear optimizing

Hi Alvaro,

Thank you for your answer. The experimental data are copied and pasted as table from the following  Thermophysical Properties of Fluid Systems ( saturation properties -temperature increments ).

The attachment is analogue file for Benzene ( i.e. no association contribution ). Here the minimization algorithm works straightforward, so I think the convergence issues are related to the association contribution ( SAFT type ).

Massimiliano

Re: Minerr/nonlinear optimizing

Hi. I can't read the original data, problems loading the mathcad document, for the benzene too.

I copy some data, and what I can see is that the first solve block fails for some points, not all of them. So, guess you can "un-refine" the interval from NIST page, or reduce the whole interval for get some one where all data points gives a solution for the minerr block. See attached. Try also to change the solve method for quasi Newton or Conj-Grad. Also, try for TOL=CTOL=0.01. You have several variables, but for T in K and P in Pa this value is actually a very very small one.

You can identify points where the solve block fails.

Best regards.

Alvaro. Re: Minerr/nonlinear optimizing

Hi,

Thank you for your indications. I will try to apply your suggestions. However the convergence of the solve block is not a "sufficient condition", if you see in most cases the two solutions coincide, while in case of benzene not, the first (0) representing the vapor, the second (1) representing the liquid, with the given reduced density initial values (  0.0001 and 0.6  ).

Massimiliano

Re: Minerr/nonlinear optimizing

Hi Massimiliano. Yes, you're right about the "sufficient condition" (<=), but it's a "necesary condition" (=>) for working the minerr block. And it's true what you say about the benzene too.

But I don't show the correct picture, playing with CTOOL make a nonsense mistake. Attached shows better what's I says: see the result for row 24 of the data.

Best regards.

Alvaro. 