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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

parameterize Minerr solve block.

ptc-4699986
1-Newbie

parameterize Minerr solve block.

I'm having trouble parameterizing a minerr solve block.

In the end I need this to iteratie through a series a guess values for parameter a inside the block.

Could anyone tell me if it is even possible to do what I want and if so how?

many thanks in advance.

20 REPLIES 20
Werner_E
25-Diamond I
(To:ptc-4699986)

minerr is an iteratiive numeric approximation, it needs a guess value.

You may write

param:=1 (or whatever guess value you think is appropriate)

before param is used the first time (that is in a:=... in your case). Usually this is done before the token "Given".

That guess value may influence what solution minerr arrives at (if there are multiple) and sometimes it decides if you get a solution at all or nothing but "no solution found" error.

Werner

defining param:= before the given statement doesn't work.

that will fix the value of param to the first definition and calling the function with a different argument value doesn't change the value of param anymore

Hi Arjen,

there are a number of issues that will stop this sheet from working.

1. resid() is returning a vector of results - it should return a single value that minerrccan try to minimise.

2. all the guess variables (b, d, e, f & g) should be defined outside the given ... minerr block

3. a must be defined inside the block, but with the boolean equals as it is defined by the value of param.

4. Minerr is not trying to minimse the residual using parameter a as this is defined so it should not appear in the minerr statement.

attached is modified to give a possible solution.

Hope this makes sense

Regards

Andy

thanks for the help but you solution doesn't work.

The parameters found are completely wrong and the result doesn't match the original data.

Is the attached any better?

Alan

Message was edited by: ALAN STEVENS Corrected file attached.

Residual equation needed correction but try this.

Regards

Andy

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

Arjen Walstra schrieb:

defining param:= before the given statement doesn't work.

that will fix the value of param to the first definition and calling the function with a different argument value doesn't change the value of param anymore

You are right, I was too quick about your sheet.

Andy was right in most of his points, I think. I am not sure about the resid function but its plausible that it should return a scalar to be able to minimize.

The main problem now, as I see it, is, that a has to be a function.

Look at the attached sheet.

By changing the parameter param only the value for f is slightly changed - the other values are left at the guess values. Thas probably not what you want. On the other hand, minerr only is given ONE constraint (resid=0) and has alot of variables to play with. As it seems Mathcad decides to play with f only,

Edited: Just reinserted your original resid function as I found a very similar example in one of the quicksheets which I think you had looked at, too. Now all variables are changed slighty. Hope it helps.

Werner

Here's yet another approach - turns the fit into a linear multivariate one.

Alan

Message was edited by: ALAN STEVENS Corrected file attached

RichardJ
19-Tanzanite
(To:Werner_E)

I am not sure about the resid function but its plausible that it should return a scalar to be able to minimize.

That depends. If you use the Levenberg-Marquardt algorithm (usually the best option) then you should pass it a vector of residuals (a matrix, or even a nested matrix, of residuals will also work). If you pass it the sum of the squares of the residuals you will get less accurate (possibly much less accurate) results. In MC15 minerr defaults to the LM algorithm, so unless you have a good reason pass it a vector of residuals. In MC11 you have to manually force it to LM. I forget which version it changed in. If you use either conjugate gradient or quasi-Newton then pass it the sum of the squares of the residuals.

Hi everyone, thanks for all the great help.

Very nice to see how many are willing to help.

Most of the solutions so far involve fixating parameter a in the model and running the regression for the other parameters. However this doesn't always generate te best possible fit.

What I have seen so far is that if I manualy change the guess value for a better solutions are found compared to fixating a to that same value (or any other).

Is there no solution to parameterize the guess value for a?

Arjen Walstra wrote:

Is there no solution to parameterize the guess value for a?

If you look at the method I used in file tempb.xmcd above you will see that 'a' is used directly as a parameter. It is then varied computationally rather than manually.

Alan

Hi Alan,

I have seen you solutions. But in all solutions "a" is removed from the regression solve block and thus forced to a value. I do see that you are computing a long array of values for "a" and use the solve block to compute the other constants. However forcing "a" to a value is not giving me the same result as looping through an array of guess values for "a"

Ok. Here's a version where 'a' is automatically chosen. However, the result still depends to some extent on the initial guess for 'a' - in particular if it's positive or negative. This is an intrinsic problem with multi-dimensional surface fits I'm afraid!

Alan

ALAN STEVENS wrote:

..., the result still depends to some extent on the initial guess for 'a' - in particular if it's positive or negative.

In fact tempd.xmcd seems to find three solution sets: a rubbish one if the initial guess for 'a' is zero; a reasonable one if it is positive and a somewhat better one if it' is negative (using the maximum relative deviation as the measure).

Which set, if any, is best for your problem only you can tell.

Alan

ALAN STEVENS wrote:

ALAN STEVENS wrote:

..., the result still depends to some extent on the initial guess for 'a' - in particular if it's positive or negative.

: a rubbish one if the initial guess for 'a' is zero;

Oops, no it's not much different! See images below.

Alan

res0.PNG

resn.PNG

resp.PNG

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

According to your original constraint a is dependend on param which is constant for a given solution!? Why do you think it shoul be considered and iterated?

the outcome of the regression depends on the initial guees value for "a".

I want to iterate through an series of guess values for "a" to find the solution with the smallest error.

my original is not a constraint it is a guess value.

a:=param/(256*.64*.64*16)

if it where a contraint it would have been

a=param/(256*.64*.64*16)

Hi Arjen,

If the value of 'a' is tom be minimised , why keep it external to the solve block?

There is sufficient information to run minerr with 1 extra solve variable.

e.g. attached

Regards

Andy

RichardJ
19-Tanzanite
(To:ptc-4699986)

In Alan's tempb worksheet change the expression arjen(a):=minerr(b,d,e,f,g) to arjen(a):=minerr(a,b,d,e,f,g). The parameter a will then be treated as a guess value, and all the parameters will be varied for the best fit. If you are going to solve for a lot of guess values you can speed it up a bit by right clicking on "minerr" and forcing it to the LM algorithm (it stops it from wasting time looknig at the CG and QN results).

Everyone many thanks for all the support.

The final adjustment suggested by Richard seems to do the trick.

Announcements

Top Tags