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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Extract Data by 2D Interpolation

Perez
12-Amethyst

Extract Data by 2D Interpolation

Hello everyone,

 

I am encountering difficulties setting up a 2D interpolation in Mathcad. My objective is to determine the parameters A, B, C, and D for two given inputs: ratio "r" and delta "δ."

 

The dataset is categorized into four groups based on Ratios: 0.25, 0.5, 2, and 4. Each group is associated with a specific set of Deltas and corresponding parameters A through D.

 

While I have managed to interpolate within a single Ratio group, my challenge arises when attempting to interpolate for a ratio value that falls outside these defined groups, such as 3.5. Attached is my Mathcad Prime 7 worksheet for reference. I appreciate any assistance you can provide.

 

Note: When the delta input "δ" exceeds the highest Delta value in a given Ratio group, the output should correspond to the highest Delta record's values, as extrapolation beyond this point is not allowed.

 

Perez_1-1710866008035.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ttokoro
20-Turquoise
(To:Perez)

Attach it.

linterp_2D function is made by Werner_E.

View solution in original post

15 REPLIES 15
LucMeekes
23-Emerald III
(To:Perez)

Your dataset is somewhat uneven. You don't have values for Ratio=0.5 and Delta=45, nor for Ratio=2 or 4 and Delta=100.

Is that purposely?

 

Luc

Perez
12-Amethyst
(To:LucMeekes)

Hello @LucMeekes , I have updated the record for a Ratio of 0.5 with Delta=45 instead of 100. All other data remains accurate. For a Ratio of 0.25 alone, there are 4 Delta rows, while the other Ratios have 3 Delta rows each.

 

Additionally, I've attached the updated worksheet in the Prime 9 version with a solution that I managed to implement using a brute force method. It is functioning as expected, despite being a brute force approach.

Perez_0-1710909535932.png

 

ttokoro
20-Turquoise
(To:Perez)

0. Make all Delta=100 data by linterp function.

image.pngimage.pngimage.pngimage.pngimage.pngvx = Ratio and vy = Delta. 

1. Using Bicubic2D function.

image.pngimage.pngimage.png

2. Using Werner_E's linterp_2D function.

image.pngimage.pngimage.pngimage.pngimage.pngimage.png

Perez
12-Amethyst
(To:ttokoro)

Thank you @ttokoro san, please attach your Mathcad prime file, I want to study it.

ttokoro
20-Turquoise
(To:Perez)

Attach it.

linterp_2D function is made by Werner_E.

You may also try splineInter_2D() for a similar result like Bicubic2D

Werner_E_0-1710983665157.png

 

Perez
12-Amethyst
(To:Werner_E)

Thank you @Werner_E and @ttokoro san, 

I tested the functions, and they are working correctly.

My next step is to research the data set to determine the most appropriate interpolation method, piecewise polynomial or linear. For instance, for Data Set A, polynomial interpolation produces a smooth peak when transitioning from a ratio of 2 to 4 for low Delta values. Any A value interpolated in that range will be higher compared to the linear interpolation method.

Below are the comparison results between my implementation (2D linear) and yours.

 

Perez_0-1710988128890.png

 

ttokoro
20-Turquoise
(To:Perez)

The difference is caused by the behavior of two functions. SplineInter_2D shows more flat shape. And linterp_2D fit all points data on the plot.

image.png

Perez
12-Amethyst
(To:ttokoro)

Thank you @ttokoro san, 

This is a good comparison plot. I will consult the data owner on their preferred method and assess the downstream impact of using the higher value. Please attach the Mathcad file so I can examine how to add the green point to the plot.

 

こちらは良い比較のプロットですね。@ttokoroさん、ありがとうございます。データの所有者に、好みの方法について相談します。また、より高い値を使用した場合の下流への影響を評価します。プロットに緑の点を追加する方法を検討するために、Mathcadファイルを添付してください。

Perez_0-1711028216714.png

 

Werner_E
24-Ruby V
(To:Perez)

To add a single point in a 3D plot you have to plot that point twice, otherwise an error is thrown.

Assign the x- and y values and then let the 2x3 matrix shown below be plotted.

Werner_E_0-1711033961735.png

What irritates me on @ttokoro 's picture is this

Werner_E_1-1711034038476.png

even though he seems to just use interpolations and not a fitting function some points seem to be not part of the surface which should not happen when using an interpolation. But maybe thats just because of a bad choice for the grid size. Can't tell as @ttokoro  unfortunately as usual did not attach the worksheet in fist place (but he sure will do later because you asked for it).

 

Speaking of surface fitting instead of interpolation - you just have 13 points of the surface at hand. Thats quite few but you can fit any surface function to the data anyway using a solve block with "minerr".  Not sure what the final intention is and IMHO a surface fit only makes sense if you know what kind of process the data stems from and what kind of (surface) function the data can be assumed to lie on.

Here an example where a simple polynomial function of second order is fitted to the data. As you can see, the fit is pretty bad and a lot of the data points are way off the surface

Werner_E_0-1711036479589.png

This was just an example to demonstrate the use of the solve block. For polynomial fits you would rather use the built-in "polyfit" function which is much more convenient.

In the next picture you see polynomial fits of third and fourth order

Werner_E_1-1711036748464.png

Prime 9 file attached

 

 

ttokoro
20-Turquoise
(To:Perez)

Werner_E shows how to do it.

Attach new sheet includes mesh number select combo box. 

Perez
12-Amethyst
(To:ttokoro)

Thank you @ttokoro san and @Werner_E ,

 

I have a question regarding the mesh: How can we keep the mesh within the limits of the data points? As illustrated in the image below, I would prefer that the mesh does not extend beyond the data points (indicated by the blue hatch).

 

Perez_0-1711205281853.png

 

 

 

ttokoro
20-Turquoise
(To:Perez)

CreateMesh makes data for Adata(x,y) of x from 0 to 4 and y from 0 to 100. So if you want x from 0.25 and y from 5, just change  CreateMesh(Adata,0.25,4,5,100, number of x mesh, number of y mesh).

image.pngimage.png

Perez
12-Amethyst
(To:ttokoro)

It's working correctly. This allows me to visually verify that the interpolated value falls within the defined surface area dictated by the available data.

 

Perez_0-1711237999274.png

 

ttokoro
20-Turquoise
(To:Perez)

If you want to know how to use built in functions, just point on the function you want to know and put F1 kye to view the help.

Top Tags