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

Level 1

## Is there any way to determine how many iterations Mathcad performed in a Minerr Nonlinear-Regression: Levenberg-Marquardt curvefit?

I am trying to check if my Minerr solution to a nonlinear-regression, Levenberg-Marquardt curvefit of a circle to data points worked correctly. I did not get an error message, so I think the iterations converged. But I cannot check simply by the error at each data point, because, obviously, it is a minimization problem, so one expects to get error at each data point - it is a best curvefit problem. I set the TOL and CTOL convergence-error values to 1e-010, and I still got no error message. So I think it converged, but I want to make sure. If I could confirm that a non-trivial number of iterations was performed, then I could be somewhat reassured. But if it stopped after, say, 2 iterations, then I would guess that something got misinterpreted by Mathcad, perhaps in the required vectorization.

9 REPLIES

## Re: Is there any way to determine how many iterations Mathcad performed in a Minerr Nonlinear-Regression: Levenberg-Marquardt curvefit?

You may be able to use the trace feature. See here for an example.

http://communities.ptc.com/message/164648#164648

## Re: Is there any way to determine how many iterations Mathcad performed in a Minerr Nonlinear-Regression: Levenberg-Marquardt curvefit?

Please provide a worksheet if you require further help.

## Re: Is there any way to determine how many iterations Mathcad performed in a Minerr Nonlinear-Regression: Levenberg-Marquardt curvefit?

You may have a look at the built in variable ERR to get a measurement about the quality of the fit. Or you calculate your own sum of squared errors (SSE).

Wouldn't a plot of the raw data and the fitted function give you a quick idea of if the iteration succeeded?

There are two ways I can think of to get information how many iterations Mathcad's built-in numeric iteration algorithms have done.

Both would require that you turn one of the expressions used into a function which is defined before the solve block. The function would return the usual result but before it does so it would...

1) [does not work in Prime] ... call trace("xxx"). If you toggle degug you can then see how many times the line xxx is shown in the debug window. With some more work you may even be able to implement a counter so you don't have to count yourself.

2) ... use any of Mathcads WRITE commands (e.g. WRITEPRN resp. ADDPRN) to write a line to a file on disk. This slows down execution considerably. You may also implement a counter - read in the content of the file, incerement and write.

## Re: Is there any way to determine how many iterations Mathcad performed in a Minerr Nonlinear-Regression: Levenberg-Marquardt curvefit?

Thanks. I will try this. I didn't know that one could make a compose program after a boolean equals. I'll let you know how it came out.

## Re: Is there any way to determine how many iterations Mathcad performed in a Minerr Nonlinear-Regression: Levenberg-Marquardt curvefit?

I just finished the ERR calculation, and confirmed that ERR was returning the square-root of the sum of the residuals (radial deviations from the circle) at each data point. I think the circle curvefit is working. I just want to be sure that Mathcad is actually doing what I intended it to do. I don't know why the forum searcher didn't return the above thread when I searched on: "maximum iterations".

## Re: Is there any way to determine how many iterations Mathcad performed in a Minerr Nonlinear-Regression: Levenberg-Marquardt curvefit?

 Dave Rosenbaum wrote:Thanks. I will try this. I didn't know that one could make a compose program after a boolean equals. I'll let you know how it came out.

Yes it's not a very well documented feature.

Yes, please let us know how you get on.

## Re: Is there any way to determine how many iterations Mathcad performed in a Minerr Nonlinear-Regression: Levenberg-Marquardt curvefit?

 Dave Rosenbaum wrote:I don't know why the forum searcher didn't return the above thread when I searched on: "maximum iterations".

Don't worry, I only managed to find it because I contributed in the thread I directed you to.

## Re: Is there any way to determine how many iterations Mathcad performed in a Minerr Nonlinear-Regression: Levenberg-Marquardt curvefit?

 Mike Armstrong wrote:You may be able to use the trace feature. See here for an example.http://communities.ptc.com/message/164648#164648

... with animation http://communities.ptc.com/videos/1460

## Re: Is there any way to determine how many iterations Mathcad performed in a Minerr Nonlinear-Regression: Levenberg-Marquardt curvefit?

 Valery Ochkov wrote:Mike Armstrong wrote:You may be able to use the trace feature. See here for an example.http://communities.ptc.com/message/164648#164648... with animation http://communities.ptc.com/videos/1460

Very clever Valery, I do recall seeing this before.

Announcements

____________________________________ If you experience problems when attaching a Mathcad sheet file ( .mcd, .xmcd or .mcdx) to the message then zip it first. To get the .zip file, use Windows Explorer, select the sheet file, right-mouse click and select "Send to" then "Compressed (zipped) folder". This results in a .zip file containing the worksheet that you can attach