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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Parameter calculation with odesolve and minerr function

ptc-4640822
1-Newbie

Parameter calculation with odesolve and minerr function

Hello all

I am trying to use the Odesolve and Minerr function in Mathcad to get the parameters of a thermal model, but having problem now.

When using the minerr function, there is an error "this variable is undefined"

I can not figure out where is the problem.

Could anyone please help?

The worksheet is attached.

I am using the mathcad14, and I saved it as mathcad 11.

Hope it can be opened.

Thanks in advance!

25 REPLIES 25

Unfortunately, I am just about to go through the door to work, so can't look in detail. However, if you trace the error back, it says there are too few initial conditions in Function (your function "Function", that is)

Stuart

Hello Stuart,

Thanks very much!

You did give me a hint, the equations should be PDEs.

I will try again with Pdesolve again.

However, I wonder if there are other ways to solve this problem.

At first I tried to fit the the Power to be a function of time, so that the equations has only one variable t, which could make the calculation simple. Unfortunately, my experimental data is is not enough. With polynomial regression, the output function P(t) varies significantly from theory and the final output value(C1,C2,R) of the minerr function is not correct. I am not sure if it is caused by the uncorrect P(t). Will this solution work if enough data are abtained with another experiment? Will the P(t) have an impact on the integral of T1(t)?

Thanks for your help!

Like this?

Alan

Improved worksheet attached.

Hello Alan,

Thanks for your reply.

I have tried with your method and the output is not correct.

Please see my attachment above.

I am not sure if it is cause by the insufficient experimental data.

Will not the P(t) have an impact on the integral of T1(t)?

Thanks!

It's not surprising that the results of your worksheet are way out, as your polynomial fit to power is totally unrepresentative of the measured powers.

Have you looked at the modified worksheet I supplied (I edited my original reply to provide a more sensible sheet)?

rosabel wang wrote:

Will not the P(t) have an impact on the integral of T1(t)?

Thanks!

Yes, it will, and the model incorporates this.

Alan

Hello Alan,

Thanks!

The output looks much reasonable now.

I will redo the experiment and get more experimental data.

Thanks very much!!!

Here is another version. I think that the Levenberg-Marquardt algorithm gives more accurate results

Viktor

Hello Viktor,

Thanks!

But I am sorry it is a little too difficult for me to understand the Minerr solve block in your worksheet.

Where is the definition of f(t)? I can not find it.

How could S(C1,C2,R) be equation to a Temperature. It is not a vector, right?

Thanks very much!

Interesting! The spline fit helps, but try using L-M with the original guesses for C1, C2 and R, and L-M doesn't work at all well! This shows a good initial guess helps enormously. Viktor presumably tried a couple of iterations as his initial guesses match his final values.

Rosabel, look carefully at Viktor's "val" function. He has defined the function "val" to take any other function "f" together with a variable "t" and ca;lculate "f(t)". The "f" is just an argument to the function "val". It doesn't matter what "f" is until "val" is called on to perform a calculation (which it does in the next line).

Alan

Hello Alan,

Thanks!

Understand now.

But still, should not the three statements in the attached worksheet be all the same?

You mentioned the impact of the intial guess value on the the final result.

I have been troubled by this problem for a long time.

How to find the initial guess value? Is there any general method?

Thanks very much!

rosabel wang wrote:

Hello Alan,

Thanks!

Understand now.

But still, should not the three statements in the attached worksheet be all the same?

No. The first statement (Viktor's function) returns the values of T1 at the times in Times. The next two return the difference between T1 and the measured Temperatures at the values in Times.

How to find the initial guess value? Is there any general method?

Not in general. If you have an understanding of the physics of the particular situation you are modelling then you generally stand a better chance of making a good guess (to within an order of magnitude, say). The greater the number of parameters you are trying to find (three in your case) the more difficult it usually is for the numerical methods to find the best value (for non-linear responses anyway), so the more important it is to get good starting guesses. Unfortunately, your system is quite sensitive to the initial guesses. Do you know anything about the thermal conductivities/capacities/resistances of the thermal system you are simulating electrically? If so you might be able to make reasonable guesses for C1, C2 and R.

Alan

Hello Alan,

I am sorry it's still not very clear to me.

For me, the three statements are just like A = B and A - B =0, and I can not see the difference.

Thanks very much for your great help!

rosabel wang wrote:

Hello Alan,

I am sorry it's still not very clear to me.

For me, the three statements are just like A = B and A - B =0, and I can not see the difference.

Thanks very much for your great help!

Perhaps the attached will help.

Alan

Thank you Alan for the detailed and comprehensive comments. I can not comment on the better - my English is too limited.

Viktor

Viktor

Rosabel, I think I misunderstood your question a little. When Viktor's function is set equal to Temprature within the Solve block it is, indeed, the equivalent of your approach using "resid". It's a matter of taste which approach you use. There's more than one way to skin a cat!

.

Viktor, I wish my Russian was as good as your English!

Alan

Hello Alan,

Understand now.

Thanks for your patience.

You really helped a lot!

Here's another version with an AdamsBDF-integrator and Given/Minerr block.

Viktor

Viktor

Hello Viktor,

Thanks!

Good to know there are so many solutions!

Hello

I did the experment again yesterday and found that the experimental data can be saved as .scv format.

It is really convenient.

However, I am having the initial guess value problem again, which I have asked before.

Unfortunately, I know little about the thermal system and have no idea what the value should be.

I guess some instruments are needed to measure it.

I tried many times, but the error is still too large and the fitting function and the experimental data differs a lot.

It seems to me that it can not be improved any more

Could anyone help give me some hint?

I will attach the worksheet and the experimental data.

The relative path is used when importing the experimental data into the worksheet, so it should be able to work when you extract it.

Thanks very much!

I am not sure if some background information will help.

I am modeling lamps in PSpice according to the paper attached and I am starting with R5W, a 5W lamp.

The author did the test on three different lamps: an automotive H4 lamp, a 500W halogen projector lamp and a 36W fluorescent lamp. The C1 and C2 are in the range of several mF to several hundreds mF and R in the range of several ohm to several hundreds ohm. So at first, I am expecting the thermal capacitance and resistance of the R5W to be in the same range too. But according to the test result above, to minimum the error, C1 has to be decreased and C2 has to be increased. This makes R smaller and smaller and becomes negtive finally, which is definitely impossible.

Where is the problem?

Did I start with a wrong initial guess value or is it the result of the wrong experimental result?

Well, there is something strange with the experimental data. The power fed into the lamp in the steady state is larger than that measured in the transient state. I have done the test twice. The result are the same.

Found something suspicious.

The max. output current of the power supply I used is 1A.

For R5W, the steady current at 12V would be around 416mA, but the inrush current may reach as much as 4.16A.

I am not sure if this is the root cause for the strange experimental result.

I will redo the test next week.

Hopefully, it will work.

Because your data is very noisy some data smoothing might help. At present the noise takes some early temperatures well below 26.

And what about the measured T2 'temperatures'? Columns 2 and 4?

Alan

Hello Alan,

Thanks for your advice.

I will try with the three built-in smoothing functions later to find out which one works better.

The temperature T1 and T2 can not be measured directly.

The resistance of a filament is a function of its temperature, so T1 is derived from the voltage and current.

The columns 1, 3 and 5 are the original experimental data.

Column 1 is time, column 3 is the current and column 5 is the voltage.

Column 2 is the column 1 added with 0.00006.

Column 4 is the column 3 added with 0.00251.

Column 6 is the column 5 added with 0.26445.

This process is to make the data start with 0A and 0V at Time 0.

Sorry for my limited English.

I am not sure if you can understand.

Looks like either the final value of power or that of temperature is wrong (or at least, not consistent with your model).

Alan

Perhaps you should have recorded more values of power between the last two values you currently have recorded. See attached.

Alan

Top Tags