Skip to main content
1-Visitor
July 15, 2016
Question

making an Loop with Mathcad

  • July 15, 2016
  • 4 replies
  • 7219 views

what i want to do is making a loop, which can do an iteration work automatically.

In this function, i put the initial value

and by using an Minerr optimization, it gives final values(which i defined as Newvalue)

and what i need to do is iteration work

so reusing this Newvalue as an initial value.

for example, if i put n=3, it should mean it iterate 3 times

for that i tried using an While loop.

but i think this is not right..because it gives same result eventhough i put different value of n.

can you help me with this problem?

4 replies

21-Topaz II
July 15, 2016

Hi Ycho-3, there are inconsistencies. You should correct and then  reattach the file.

Greetings FM.

ycho-3.jpg

The logical operation, as the argument of tanh, is somewhat unusual. I would avoid as there is enough space to write.

19-Tanzanite
July 15, 2016

Your loop does nothing more than assign Newvalue to the variable Function (which is a variable, not a function, regardless of what you choose to name it) n times. So why do you think the value of Function will change? It is the same as calling the local assignment x<--3 n times. The answer will always be 3.

It is possible to take the results from the minerr optimization and call minerr again with those results as guess values, but it will not achieve anything. Minerr has converged to a minimum, and returns the values of the parameters at the minimum. If you use those values as guess values then minerr will immediately converge to the same minimum, and return the same parameter values.

Perhaps you should explain what your end goal is. What are you trying to achieve?

ycho-31-VisitorAuthor
1-Visitor
July 18, 2016

Ultimately what i want to achieve is getting an optimized value even after i put general value(like 1 ) into initial value.

right now it is not possible, if i put general value into an initial value, it occurs an error.

And my professor thought that error will be figured out if i make a loop.

19-Tanzanite
July 18, 2016

Sorry, but it's still not clear. Minerr is iterative. You give is some guess values (your initial values) for the fitting parameters. It then changes the parameters iteratively in such a way that it heads downhill on the error surface. When it gets to a minimum it stops. There is no guarantee that the minimum it finds is the global minimum, and other things, such as flat spots or discontinuities, can also make it stop. If the problem is well behaved then the guess values don't matter much, and it will converge to the same (global) minimum regardless of what they are. If the problem is badly behaved, and as I noted here: Minerr/nonlinear optimizing, yours is very badly behaved, then the guess values matter a lot. There is nothing you can do that will make any downhill optimization method work well with a surface that has discontinuities and multiple minima. You can try different guess values, but in your case there seem to be many minima and/or discontinuities.

In general, taking the results from minerr and feeding them back in as new guess values will get you nowhere, because those values already represent a minimum. In this case it does actually improves the minimization (see other posts in this thread). There is still no guarantee that you have found the global minimum though. Is this what you were trying to do?

25-Diamond I
July 15, 2016

As I understand you want to use the results of the minerr optimization as guess values for the very same optimization!? Why? Its unlikely you will get different values the second time as Mathcad iterates on its own until it decides that the result is good enough (which admittedly is not always the case).

But you could achieve this by turning the solve block into a function:

12-Amethyst
July 15, 2016

Hi Yooney.

I don't think that Einstein could says that "Insanity is doing the same thing over and over again, but expecting different results” because don't apply in a lot of places.

Best regards.

Alvaro.

insanity.gif

19-Tanzanite
July 15, 2016

Well, that's a surprise! What you are observing should not happen in a well behaved minimization problem. I suspect the issue is the THE variable, which is discontinuous. Downhill type numeric solvers (which includes all of the minerr algorithms) do not like discontinuities in the error surface. To make things worse, THE is wrapped into d and f, which in turn are wrapped into the return value of Fit(X, Delta). So I suspect there are actually many discontinuities in the error surface, and they cause minerr to stop at arbitrary points. Restarting it at those points allows it to go downhill again until it hits another discontinuity, and again stops.

12-Amethyst
July 15, 2016

Hi Richard. Very good point. Actually, round off errors can be interpreted in the same way.

Best regards.

Alvaro.