Skip to main content
1-Visitor
October 2, 2013
Solved

Is it possible to record how minerr() change the parameter?

  • October 2, 2013
  • 2 replies
  • 2379 views

Hi:

My code contains 3 parameters (x1,x2,a2) and uses minerr(x1,x2,a2) to shoot a minimum error.

In the code, I first give 3 initial values to x1,x2,a2 (Ex: x1=3, x2=3, a2=3).

Then minerr(x1,x2,a2) returns me another 3 values of x1,x2,a2 (Ex: x1=1, x2=1, a2=1).

My question is:

I know minerr() utilize LMA to find x1=1, x2=1, a2=1 after several loops.

Is there any bulit-in function or written code can be use to record how minerr() find x1=1, x2=1, a2=1?

The reason of asking this question is for code debug purpose...

Best answer by Werner_E

OK, I've been thinking about it and have found a solution. If you use a dummy function which contains trace commands you can follow the algorithm if you turn on debugging. Don't forget to remove the dummy function and turn off debugging when not needed as it will slow down operation significantly and I know from a former thread that you have very long running iterations 😉 Did you came to a solution there?

I tried with an example from the quicksheets - see attached

Instead of using trace you could write the values of the parameters to a file and as you can also read files in that dummy routine you even could make a counter counting the iteration steps. But of course disk reads and writes would slow down operation even more.

I still wonder how tracing the LMA would help you in any way.

03.10.png

2 replies

25-Diamond I
October 2, 2013

As far as I am aware there is no way to get interim results using Mathcads minerr().

But then, why would you like to debug a built-in routine? You don't have access to and can't change the code anyway.

Unless of course you write your own minerr routine 😉 But then you could throw in your own trace() commands for debugging purposes, too.

1-Visitor
October 2, 2013

Hi:

Got it!!

I try to avoid writting my own minerr routine at this moment (a big pain).

I don't think minerr() has any problem and just want to look how parameters change in each loop.

The problem I am facing now is: the code gives me the unwanted result and even disobeys constraints I setup.

Since the code can run, I don't know know to fix it (I checked the code structure with my advisor and he said the structure is fine).

I hope MathCad has the same function like Labview to show the parameter change in an animation way.

Werner_E25-Diamond IAnswer
25-Diamond I
October 3, 2013

OK, I've been thinking about it and have found a solution. If you use a dummy function which contains trace commands you can follow the algorithm if you turn on debugging. Don't forget to remove the dummy function and turn off debugging when not needed as it will slow down operation significantly and I know from a former thread that you have very long running iterations 😉 Did you came to a solution there?

I tried with an example from the quicksheets - see attached

Instead of using trace you could write the values of the parameters to a file and as you can also read files in that dummy routine you even could make a counter counting the iteration steps. But of course disk reads and writes would slow down operation even more.

I still wonder how tracing the LMA would help you in any way.

03.10.png

1-Visitor
October 3, 2013

I would suggest trying to figure how to graph the equations involved. Solver routines, particularly those that use something Newton-Raphson-ish, tend to have problems when the function is changing signs near the solution.

25-Diamond I
October 3, 2013

Mo Det wrote:

I would suggest trying to figure how to graph the equations involved. S

How? Chih-Yu Jen has 3 independend parameters and the function result may be a vector, not a scalar.

In a prior post (http://communities.ptc.com/message/208636#208636) he had up to 25 independend variables and the result was a vector with up to 1500 elements!

Furthermore, if we had just a scalar function with only one parameter, I would expect the function to change sign at the solution. After all we a searching parameter(s) which make a function (close) to zero. Not sure what exactly you have in mind and how it would affect the Levenberg-Marquardt algorithm in question.

Can you elaborate more on that?