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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

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

ptc-5146913
1-Visitor

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

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...

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:ptc-5146913)

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

View solution in original post

7 REPLIES 7
Werner_E
25-Diamond I
(To:ptc-5146913)

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.

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_E
25-Diamond I
(To:ptc-5146913)

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

Hi:

Thanks!!

I found a proper model to generate 25TTs by the use of 3 parameters.

Attach is the code I am using now (no raw data included) and the TXT file contains the LMA tracing result.

Questions:

1) Do the think this code (minerr()) does the right thing?

I mean:

3 parameters generate 25TTs-->25n, theta--> calculate "t"-->calculate UR(TT)-->change 3 parameters to make UR(TT)=0-->repeat.....

It's weird that minerr() doesn't follow constraints and finally return to the initial guess values.

2) From the trace command I can see how 3 parameters change.

I tried to trace UR(TT) but didn't work. Any suggestion?

Werner_E
25-Diamond I
(To:ptc-5146913)

1) Do the think this code (minerr()) does the right thing?

I mean:

3 parameters generate 25TTs-->25n, theta--> calculate "t"-->calculate UR(TT)-->change 3 parameters to make UR(TT)=0-->repeat.....

It's weird that minerr() doesn't follow constraints and finally return to the initial guess values.

2) From the trace command I can see how 3 parameters change.

I tried to trace UR(TT) but didn't work. Any suggestion?

1) no idea

not weird, thats the difference between find() and minerr(). find may fail but minerr will give you the best it can find. Richard showed how to weight constraints but none of them will be hard ones.

2) maybe it works if you assign UR(TT) to a variable in dummy and then try to trace that variable. tracing large vectors can be a problem with trace.

Is it on purpose that in UR(TT) IM[i is the absolute value of the REAL part of make_theory, not the imaginary part? Yyou could speed up calculation if you assign the output of make_theory to a variable so you have to call that routine omly once, not twice.

It seems to me that UR(TT) is not doing what you intend. The result would be a vector which contains the partial Sums of what you call error.

You could use instead

04.10.png

or in my opinion better instead of UR(TT)=0 use in the solve block

04.10.png

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.

Werner_E
25-Diamond I
(To:arbiter007)

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?

Announcements

Top Tags