Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


2 Pages12>
Options
Go to last post Go to first unread
Offline brotjob  
#1 Posted : 21 January 2024 00:41:04(UTC)
brotjob


Rank: Advanced Member

Groups: Registered
Joined: 18/09/2014(UTC)
Posts: 71
Switzerland

Was thanked: 7 time(s) in 7 post(s)
Hi,
I want to create a table for interpolating saturation steam pressure in a PL controller. The PLC allows 120 setpoints that I can define individually. The PLC will do linear interpolation between the two nearest setpoints. I want to get the highest possible accuracy.

So how do I define the setpoints for temperature in order to get the best accuracy for saturation steam pressure?

I am aware that there might be more than one solution i.e. one for lowest absolute error and one for lowest relative error. However I do not have sufficient mathematical and Smath-specific knowledge to do it myself. I read about inverse distance weighting but what I need is somehow the opposite since I can choose the setpoints.

Attached is a sheet with the formula
Sattigungsdampfdruck-Stutzpunktberechnung.sm (14kb) downloaded 8 time(s).

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Jean Giraud  
#2 Posted : 21 January 2024 05:53:32(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
IAPWS-97 is scalar. From a for loop, create/range your table.
wrt your PLC [Programmable Logic Controller]
ramp a linear SP over 120 elements. Next demo.
Please, confirm it works. Jean

Sattigungsdampfdruck-Stutzpunktberechnung.sm (39kb) downloaded 4 time(s).
thanks 1 user thanked Jean Giraud for this useful post.
on 25/01/2024(UTC)
Offline brotjob  
#3 Posted : 21 January 2024 06:29:02(UTC)
brotjob


Rank: Advanced Member

Groups: Registered
Joined: 18/09/2014(UTC)
Posts: 71
Switzerland

Was thanked: 7 time(s) in 7 post(s)
Dear Jean
Thank you for the advice. I must admit I have difficulties understanding what you are saying. In your sheet I see an alternative formula for calculating saturation steam pressure. That was not what I was looking for.

I am looking for a method that with a given formla E(t) for saturation steam pressure over temperature will return a list of interpolation points for temperature. I do not want do do this by trial and error since there are 120 parameters to vary. Once I have the list with temperatures I will run them through the formula e(t) thus creating a table with two rows one for t one for E and 120 columns.

Edited by user 21 January 2024 06:31:50(UTC)  | Reason: be more specific

Offline mkraska  
#4 Posted : 21 January 2024 10:50:58(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,988
Germany

Was thanked: 1126 time(s) in 723 post(s)
This method assumes that the error in linear interpolation is related to the curvature. The problem is reduced from 120 parameters to just a few.
You still have to adjust them by hand, according to what your understanding of optimal distribution is. I tried to minimize the maximum absolute error.

Note that for 120 points, you probably need to increase the sampling points of the plot to not undersample the error.

2024-01-20 21_49_21-SMath Solver - [Optimal sampling points_Kr.sm].png
Optimal sampling points_Kr.sm (29kb) downloaded 11 time(s).

Edited by user 21 January 2024 10:56:33(UTC)  | Reason: Not specified

Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
thanks 1 user thanked mkraska for this useful post.
on 22/01/2024(UTC)
Offline Jean Giraud  
#5 Posted : 22 January 2024 04:21:13(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: brotjob Go to Quoted Post
I am looking for a method that with a given formula E(t) for saturation steam pressure over temperature will return a list of interpolation points for temperature. I do not want do do this by trial and error since there are 120 parameters to vary. Once I have the list with temperatures I will run them through the formula e(t) thus creating a table with two rows one for t one for E and 120 columns.

You mean bar(°C) ... not anything E(t)
There is noting to solve wrt IAPWS-97
Construct the 120 pairs from a for loop.
Range 't' as you wish ... export to PLC.
Jean

Offline Jean Giraud  
#6 Posted : 22 January 2024 05:19:18(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
At this point, as far as it might mean,
at each PLC scan, it will take the next 't,bar(t)'

Worksheet64 bar(degC).sm (28kb) downloaded 3 time(s).
Offline Jean Giraud  
#7 Posted : 23 January 2024 05:34:51(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
The other perfect option is to establish the XFR of bar(°C)
XFR [Transfer Function]
Range at will over 120 points, plug in PLC.
XFR is the graphical representation of a system open loop
moving from steady state 0 to another state W/O oscillations
This is why the discrete XFR is the perfect option.
Jean

Offline brotjob  
#8 Posted : 25 January 2024 07:20:32(UTC)
brotjob


Rank: Advanced Member

Groups: Registered
Joined: 18/09/2014(UTC)
Posts: 71
Switzerland

Was thanked: 7 time(s) in 7 post(s)
Thank you so much for your replies!

Especially the answer of Martin Kraska looks promising.

As far as I understand it is a major problem that the curve I used in the first row consists of two formulas. So it would be complicated to determine how many sampling points should be assigned to the low and high temperature range. Hence the idea of Jean Giraud is good to use a formula that is valid for the entire range in question. I integrated this IAPWS-97 formula in Martin Kraskas example.

I am not convinced that this question is too much about "taste". With a given assumption there should be a limited number of solutions. This is an optimisation problem. And I assume least squares would be the method to go. So I can either create a solution that minimizes absolute error (guess the unit would be Pa*K) and one that mininizes percentual (relative) error.

In Martins example I marked those parameters that are input as green. There remain four parameters that need calculation. One of them is determined by T.max but I do not see the formula for calculating h.0 out of T.max so any help appreciated.

The example below does not work because Smath cannot calculate the second derivative. I don't know why, this should be possible.

@Jean: H have not understood part of what you are trying to say. What are wrt and XFR? Then I think you have not understood what I am actually trying. I am looking for X in Martins example.

Again, thank you so much for the ideas provided!

Optimal sampling points_v2.sm (27kb) downloaded 4 time(s).
Offline Jean Giraud  
#9 Posted : 25 January 2024 09:08:46(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: brotjob Go to Quoted Post
The example below does not work because Smath cannot calculate the second derivative. I don't know why, this should be possible.

@Jean: H have not understood part of what you are trying to say. What are wrt and XFR? Then I think you have not understood what I am actually trying. I am looking for X in Martins example

Confirmed: IAPWS-97 does not support derivative.
If you discretize/spline, you can have first, 2nd, third, fourth derivatives
from infinitesimal analysis.
Forget XFR. IAPWS-97 not compatible Laplace.
On the other hand, you can populate from the code logpts
Jean

Offline overlord  
#10 Posted : 26 January 2024 04:38:08(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,128
Turkey

Was thanked: 509 time(s) in 339 post(s)
Originally Posted by: brotjob Go to Quoted Post
@Jean: H have not understood part of what you are trying to say.

Don't bother, he doesn't have any intention to help you.
He is the master troll of this forum, the great nuisance.
Jean's only interest is promoting his worksheets.
Whether they are related with the question or not.
I really don't know the motivation behind it.
Is he getting paid per download of his samples?
I can't really tell, because he never posts anything useful.
Offline brotjob  
#11 Posted : 26 January 2024 05:21:19(UTC)
brotjob


Rank: Advanced Member

Groups: Registered
Joined: 18/09/2014(UTC)
Posts: 71
Switzerland

Was thanked: 7 time(s) in 7 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post

Confirmed: IAPWS-97 does not support derivative


So I guess we have to go back to Magnus formula which supports second order derivative.

The new sheet does not give an error anymore but still does not make sense nor does it show the error or solve an optimisation problem:

Optimal sampling points_v3.sm (26kb) downloaded 2 time(s).
Offline Jean Giraud  
#12 Posted : 26 January 2024 09:11:27(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: brotjob Go to Quoted Post
So I guess we have to go back to Magnus formula which supports second order derivative.

The new sheet does not give an error anymore but still does not make sense nor does it show the error or solve an optimisation problem:

You mean back to square one to your original demand; 2 rows of 120 cols
that you can plug in the PLC, all in ultimate accuracy.

Worksheet64 bar(degC).sm (28kb) downloaded 3 time(s).

Offline brotjob  
#13 Posted : 26 January 2024 21:08:06(UTC)
brotjob


Rank: Advanced Member

Groups: Registered
Joined: 18/09/2014(UTC)
Posts: 71
Switzerland

Was thanked: 7 time(s) in 7 post(s)
@Jean: The sampling points in your example are evenly distributed. I already had such a table before I posted here. This is not what I need. The result of such a table is not of "ultimate accuracy" because the curve to be interpolated is much more curved on the high side. Second derivative (curvature) is about 64 times stronger at 60 °C than on -25 °C. Thus I need more points in the high temperature range.
Offline Jean Giraud  
#14 Posted : 27 January 2024 04:39:14(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: brotjob Go to Quoted Post
@Jean: The sampling points in your example are evenly distributed. I already had such a table before I posted here. This is not what I need. The result of such a table is not of "ultimate accuracy" because the curve to be interpolated is much more curved on the high side. Second derivative (curvature) is about 64 times stronger at 60 °C than on -25 °C. Thus I need more points in the high temperature range.

1. AFAIK,there is no known technical accuracy.
2. Split the ranges of your choice mesh at will, stack.

Inst_IAPWS region 1 DECADES.sm (54kb) downloaded 1 time(s).

Offline overlord  
#15 Posted : 27 January 2024 12:17:56(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,128
Turkey

Was thanked: 509 time(s) in 339 post(s)
Originally Posted by: brotjob Go to Quoted Post
Thus I need more points in the high temperature range.

Could finding X positions which divide area under the curve into equal segments be the answer?
I am not a mathematician, just a simple engineer. Thus this reply can be totally wrong.
If so sorry for that priorly. I would really be ashamed if I made myself a fool.

PS: I couldn't make any solvers work while integral boundary is unknown.
For that, I used maple. And this made calculation very very slow.
If there is a faster and embedded way (no maxima), I would like to know.
Because I don't know.

Regards

area_divide.sm (10kb) downloaded 2 time(s).

2024-01-27_01-42.png

Edited by user 27 January 2024 12:43:27(UTC)  | Reason: Not specified

Offline mkraska  
#16 Posted : 27 January 2024 23:00:46(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,988
Germany

Was thanked: 1126 time(s) in 723 post(s)
Originally Posted by: overlord Go to Quoted Post

Could finding X positions which divide area under the curve into equal segments be the answer?


This would work only if the value of the function is proportional to it's curvature, e.g. exp(), sin().

In order to check the approach, make a plot of the error just like further above in my previous post.
Essentially, this is a minimax problem, where you want to minimize the maximum error. It should be sufficient to sample the error at the sampling points and in the center of the intervals.

Perhaps an evolutionary algorithm would be worth a try. The variables are the step sizes h_i. After each recombination/mutation step, you have to calibrate the h_i to enforce the boundary condition of the total x range.

Here is a version with evaluation of the error. This helps with setting the centering parameter.

There are two versions giving the same result.

2024-01-27 13_15_03-SMath Solver - [Optimal sampling points_Kr.sm].png
Optimal sampling points_Kr.sm (45kb) downloaded 2 time(s).

Edited by user 28 January 2024 02:16:02(UTC)  | Reason: Not specified

Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
thanks 1 user thanked mkraska for this useful post.
on 28/01/2024(UTC)
Offline brotjob  
#17 Posted : 28 January 2024 07:22:08(UTC)
brotjob


Rank: Advanced Member

Groups: Registered
Joined: 18/09/2014(UTC)
Posts: 71
Switzerland

Was thanked: 7 time(s) in 7 post(s)
Great, thank you so much Martin!

Your approach up to now had the disadvantage it only worked for positive Celsius temperatures. I made a version that fixes this. First I made symbolical calculation possible and simplified the function:
simplify-SDD.png

The challenge (for me) was to calculate the curvature symbolically. This was possible with some simplifications and the Maxima diff function instead of the built-in one.
curvature-SDD.png

Then I calculated the root mean square (RMS) error which can be minimised in a next step:
RMS-error.png

I think it is better to minimise the RMS error instead of the max error. For an engineering application anything bigger than T.max will be considered "big". So I don't care about the max. error too much as long as it is at one of the ends of the interpolation range.

For my final solution I can only enter the X values in °C with one decimal place. This will have a minor impact on the result. That's why I added a rounding function.

What I did not understand in the sheet above is why you calculate E(X) twice. Is that just an alternate approach?

How do I do the actual optimisation?

Optimal sampling points_Kr-bj.sm (68kb) downloaded 4 time(s).
Offline mkraska  
#18 Posted : 28 January 2024 08:08:32(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,988
Germany

Was thanked: 1126 time(s) in 723 post(s)
Nice to see successful applications of Maxima Wink

The two implementations of E(X) give the same result. I added the if-based one because it might be easier to understand. Not everyone is familiar with convolutions.

I wonder why you put a lot of effort in minimizing the error and then being satisfied with some RMS instead of a rigid bracketing. I am not sure at all that I understand your concept of error.

As to the optimization: Do you have to solve multiple such problems or just this one? In the latter case just be pragmatic and play around with the parameters until you are satisfied. There is next to nothing an optimizer could gain in the given example.

As I said, for a general solution I'd skip the curvature based approach and use brute force evolutionary algorithm.
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
Offline Jean Giraud  
#19 Posted : 28 January 2024 14:04:34(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: brotjob Go to Quoted Post
Your approach up to now had the disadvantage it only worked for positive Celsius temperatures. I made a version that fixes this. First I made symbolical calculation possible and simplified the function:

Below the triple point of Water [0.01°C], the function is ice sublimation.
Exists in Smath from source, down to -90 °C

Offline brotjob  
#20 Posted : 29 January 2024 04:01:05(UTC)
brotjob


Rank: Advanced Member

Groups: Registered
Joined: 18/09/2014(UTC)
Posts: 71
Switzerland

Was thanked: 7 time(s) in 7 post(s)
Originally Posted by: mkraska Go to Quoted Post
I wonder why you put a lot of effort in minimizing the error and then being satisfied with some RMS instead of a rigid bracketing. I am not sure at all that I understand your concept of error.


In an engineering application it's generally more about relative error instead of absolute error. I modified your example in order to show relative error and surprisingly the needed exponent p becomes negative! Means I need more points in the low temperature range than in the high temperature range. Blue is absolute error, red is relative error:

SDD-graph.png

Originally Posted by: mkraska Go to Quoted Post

As to the optimization: Do you have to solve multiple such problems or just this one? In the latter case just be pragmatic and play around with the parameters until you are satisfied. There is next to nothing an optimizer could gain in the given example.


I don't have many problems like this. I would like to do another one for the inverse function and one for the derivative. But I agree that for this purpose the room for optimisation is small. The red curve is amplified by 1000 so I have a peak error of 3.7 ‰ at the end and average errors less than 0.5 ‰ in the middle range. In order to further improve I would have to reduce the discretization error but that would require different hardware.

This was an interesting exercise I enjoyed much, thanks for contributing!

Optimal sampling points_Kr-bj2.sm (61kb) downloaded 2 time(s).
Users browsing this topic
Guest
2 Pages12>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.