Appropriate equation to fit this 2-Dimensional non-linear data

239 views Asked by At

To provide a brief background, I am working on a project to control the velocity of a bi-stable solenoid and I am trying to create a state-space representation of the system. One of the variables in my state-space is F, the force on the armature of the solenoid. F is dependent on the specific geometric configuration of the solenoid and the BH-curves of the ferrite cores and permanent magnet. F can be described as a function of position of the armature, x, and the current in the solenoid, i, otherwise written as F = g(x,i).

The attached excel sheet is data collected from a Maxwell finite element model of the solenoid that gives the force (in N) on the solenoid with respect to position (in mm) and current (in A). From papers I've read online (1 and 2), it is common practice to fit this curve to a bicubic spline approximation. The bicubic spline approximation can be represented as shown below.

F(t) = g(i,x) = g_0(x) + g_1(x)*i + g_2(x)*i^2 + g_3(x)*i^3

Where g_i(x) = α_i,1 + α_i,2*x + α_i,3*x^2 + α_i,4*x^3 for i=1,2,3,4

From this equation, you get 16 coefficients to fit to your data. I tried fitting to the attached excel data but it wasn't able to fit the highly non-linear forces near 0mm and 4.895mm and ended up with a high MSE = 163.05.

My method for fitting the data was done in Matlab using the nlinfit() function. If you want to replicate my results, I got α coefficients as follows:

[α_11, α_12, α_13, α_14, α_21, α_22, α_23, α_24, α_31, α_32, α_33, α_34, α_41, α_42, α_43, α_44] = [59.6556, -104.012, 49.6096, -6.9047, -14.8646, 9.3209, -1.8018, -0.0318, -0.2990, 0.8670, -0.4706, 0.0661, 0.0971, -0.0944, 0.0197]

Here is a plot of the fitted curve versus the actual data (in red).

Force Curve Fit

I believe its the function I am fitting that is the issue rather than my method of fitting. But, I don't know what the best equation to use as I don't think increasing polynomial order will help (but maybe I am wrong).

If anyone has suggestions on either figuring out how to find a good equation to fit to, or has suggestions on a particular equation that you think is appropriate for this data, I would greatly appreciate it! The data is very symmetrical in both of the input variable, current and position, which I think could be useful in finding the appropriate equation to fit.

Thank you.

Edit: Forgot to attach the excel data. Run the code snippet to generate the table of data.

<table><tbody><tr><th> </th><th>-7</th><th>-6</th><th>-5</th><th>-4</th><th>-3</th><th>-2</th><th>-1</th><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>i (A)</th></tr><tr><td>4.895</td><td>30.002332</td><td>21.985427</td><td>6.810482</td><td>-15.670808</td><td>-45.233394</td><td>-77.215051</td><td>-105.258626</td><td>-125.69229</td><td>-137.533424</td><td>-144.608218</td><td>-149.37894</td><td>-153.029304</td><td>-155.689815</td><td>-157.477955</td><td>-158.626949</td><td> </td></tr><tr><td>4.845</td><td>30.232465</td><td>24.087844</td><td>14.620048</td><td>1.72655</td><td>-14.792426</td><td>-35.152992</td><td>-59.469883</td><td>-84.288</td><td>-102.159215</td><td>-114.172775</td><td>-123.557279</td><td>-130.950597</td><td>-136.22158</td><td>-139.785929</td><td>-142.188687</td><td> </td></tr><tr><td>4.795</td><td>30.421325</td><td>24.932531</td><td>17.444529</td><td>7.892998</td><td>-3.856977</td><td>-18.014886</td><td>-34.99118</td><td>-54.76071</td><td>-73.12193</td><td>-87.497601</td><td>-98.824193</td><td>-108.060712</td><td>-114.987903</td><td>-120.253359</td><td>-124.356373</td><td> </td></tr><tr><td>4.745</td><td>30.551303</td><td>25.391767</td><td>18.870906</td><td>10.957517</td><td>1.538053</td><td>-9.535194</td><td>-22.598697</td><td>-38.389555</td><td>-55.208053</td><td>-69.556258</td><td>-81.254268</td><td>-90.739807</td><td>-98.322417</td><td>-104.256711</td><td>-108.853733</td><td> </td></tr><tr><td>4.695</td><td>30.664703</td><td>25.675715</td><td>19.70439</td><td>12.733737</td><td>4.693012</td><td>-4.564309</td><td>-15.382383</td><td>-28.781825</td><td>-44.015781</td><td>-57.405663</td><td>-68.654996</td><td>-78.136226</td><td>-85.96381</td><td>-92.262205</td><td>-97.271558</td><td> </td></tr><tr><td>4.645</td><td>30.727753</td><td>25.865955</td><td>20.238259</td><td>13.853267</td><td>6.664413</td><td>-1.448761</td><td>-10.800537</td><td>-22.615818</td><td>-36.367379</td><td>-48.848877</td><td>-59.549314</td><td>-68.920612</td><td>-76.813046</td><td>-83.32022</td><td>-88.600393</td><td> </td></tr><tr><td>4.395</td><td>30.865921</td><td>26.241471</td><td>21.290271</td><td>16.08672</td><td>10.626372</td><td>4.839985</td><td>-1.602854</td><td>-9.43494</td><td>-18.83834</td><td>-28.636958</td><td>-37.691591</td><td>-45.92364</td><td>-53.263184</td><td>-59.60791</td><td>-64.797286</td><td> </td></tr><tr><td>4.145</td><td>31.095974</td><td>26.462957</td><td>21.68939</td><td>16.805136</td><td>11.820302</td><td>6.696608</td><td>1.18386</td><td>-5.121618</td><td>-12.593724</td><td>-20.872655</td><td>-28.902156</td><td>-36.190138</td><td>-42.81756</td><td>-48.711318</td><td>-53.733812</td><td> </td></tr><tr><td>3.895</td><td>31.46129</td><td>26.783809</td><td>22.050232</td><td>17.24325</td><td>12.414941</td><td>7.549917</td><td>2.463171</td><td>-3.126318</td><td>-9.525282</td><td>-16.772883</td><td>-24.024533</td><td>-30.735935</td><td>-36.907371</td><td>-42.495141</td><td>-47.386621</td><td> </td></tr><tr><td>3.645</td><td>31.84872</td><td>27.13964</td><td>22.399963</td><td>17.609472</td><td>12.824883</td><td>8.054302</td><td>3.167199</td><td>-2.022925</td><td>-7.798272</td><td>-14.333423</td><td>-20.98601</td><td>-27.322197</td><td>-33.20454</td><td>-38.422392</td><td>-43.441491</td><td> </td></tr><tr><td>3.395</td><td>32.321379</td><td>27.611153</td><td>22.830246</td><td>18.00384</td><td>13.186564</td><td>8.407782</td><td>3.614684</td><td>-1.377083</td><td>-6.778505</td><td>-12.763999</td><td>-18.950497</td><td>-24.996769</td><td>-30.700952</td><td>-36.002519</td><td>-40.845001</td><td> </td></tr><tr><td>3.145</td><td>32.912865</td><td>28.117376</td><td>23.297908</td><td>18.414747</td><td>13.541529</td><td>8.720016</td><td>3.953985</td><td>-0.893617</td><td>-6.030829</td><td>-11.646948</td><td>-17.480042</td><td>-23.272051</td><td>-28.818368</td><td>-34.05723</td><td>-38.898901</td><td> </td></tr><tr><td>2.895</td><td>33.461235</td><td>28.733026</td><td>23.846096</td><td>18.900341</td><td>13.945926</td><td>9.043626</td><td>4.247023</td><td>-0.554529</td><td>-5.54091</td><td>-10.874341</td><td>-16.437732</td><td>-22.017734</td><td>-27.450488</td><td>-32.671967</td><td>-37.55842</td><td> </td></tr><tr><td>2.645</td><td>34.20239</td><td>29.399207</td><td>24.450979</td><td>19.429789</td><td>14.378361</td><td>9.384043</td><td>4.50818</td><td>-0.228657</td><td>-5.110888</td><td>-10.256221</td><td>-15.598685</td><td>-20.988768</td><td>-26.283234</td><td>-31.452038</td><td>-36.351057</td><td> </td></tr><tr><td>2.395</td><td>34.914372</td><td>30.186026</td><td>25.182228</td><td>20.081931</td><td>14.90649</td><td>9.757508</td><td>4.793411</td><td>-0.022121</td><td>-4.818618</td><td>-9.801554</td><td>-14.977042</td><td>-20.209359</td><td>-25.40338</td><td>-30.537892</td><td>-35.491473</td><td> </td></tr><tr><td>2.145</td><td>35.805782</td><td>31.056782</td><td>26.042754</td><td>20.849744</td><td>15.526359</td><td>10.206612</td><td>5.079032</td><td>0.217373</td><td>-4.533031</td><td>-9.394064</td><td>-14.424973</td><td>-19.520352</td><td>-24.601559</td><td>-29.643549</td><td>-34.578382</td><td> </td></tr><tr><td>1.895</td><td>36.912236</td><td>32.230447</td><td>27.190092</td><td>21.88521</td><td>16.388134</td><td>10.852426</td><td>5.512241</td><td>0.53729</td><td>-4.252576</td><td>-9.060047</td><td>-13.988674</td><td>-18.990227</td><td>-23.997652</td><td>-28.971069</td><td>-33.911535</td><td> </td></tr><tr><td>1.645</td><td>38.220177</td><td>33.55963</td><td>28.522922</td><td>23.132328</td><td>17.438377</td><td>11.652987</td><td>6.043032</td><td>0.901</td><td>-3.941164</td><td>-8.721107</td><td>-13.565417</td><td>-18.470008</td><td>-23.400995</td><td>-28.283206</td><td>-33.172001</td><td> </td></tr><tr><td>1.395</td><td>40.089435</td><td>35.460059</td><td>30.362062</td><td>24.861205</td><td>18.933028</td><td>12.805265</td><td>6.809413</td><td>1.39481</td><td>-3.583199</td><td>-8.390298</td><td>-13.200262</td><td>-18.057954</td><td>-22.938035</td><td>-27.768679</td><td>-32.61952</td><td> </td></tr><tr><td>1.145</td><td>42.604155</td><td>38.034489</td><td>32.852205</td><td>27.179704</td><td>21.024509</td><td>14.456797</td><td>7.936568</td><td>2.129503</td><td>-3.092501</td><td>-7.988163</td><td>-12.808929</td><td>-17.635859</td><td>-22.475901</td><td>-27.255258</td><td>-32.039299</td><td> </td></tr><tr><td>0.895</td><td>46.740509</td><td>42.104713</td><td>36.736597</td><td>30.755343</td><td>24.224614</td><td>17.087908</td><td>9.853802</td><td>3.360219</td><td>-2.293161</td><td>-7.426018</td><td>-12.358482</td><td>-17.254878</td><td>-22.122863</td><td>-26.910174</td><td>-31.65453</td><td> </td></tr><tr><td>0.645</td><td>53.63405</td><td>48.823341</td><td>43.145538</td><td>36.706073</td><td>29.56244</td><td>21.689267</td><td>13.405102</td><td>5.735263</td><td>-0.786028</td><td>-6.417941</td><td>-11.659605</td><td>-16.769755</td><td>-21.760135</td><td>-26.617262</td><td>-31.321544</td><td> </td></tr><tr><td>0.395</td><td>66.719783</td><td>61.669457</td><td>55.479065</td><td>48.279934</td><td>40.173712</td><td>31.232975</td><td>21.372923</td><td>11.406692</td><td>2.961089</td><td>-3.87916</td><td>-10.044617</td><td>-15.840246</td><td>-21.29497</td><td>-26.408778</td><td>-31.159668</td><td> </td></tr><tr><td>0.25</td><td>81.066195</td><td>75.939181</td><td>69.61686</td><td>62.097845</td><td>53.400235</td><td>43.453173</td><td>31.99206</td><td>19.510149</td><td>8.697597</td><td>0.08383</td><td>-7.513168</td><td>-14.397559</td><td>-20.598789</td><td>-26.139851</td><td>-31.007816</td><td> </td></tr><tr><td>0.2</td><td>88.630566</td><td>83.616297</td><td>77.408061</td><td>69.893348</td><td>60.994658</td><td>50.53292</td><td>38.266849</td><td>24.550308</td><td>12.460448</td><td>2.685077</td><td>-5.844277</td><td>-13.434216</td><td>-20.125472</td><td>-25.947463</td><td>-30.897252</td><td> </td></tr><tr><td>0.15</td><td>98.70275</td><td>93.957875</td><td>87.989331</td><td>80.562783</td><td>71.487536</td><td>60.477972</td><td>47.235774</td><td>32.081579</td><td>18.171011</td><td>6.62184</td><td>-3.316554</td><td>-11.987794</td><td>-19.434567</td><td>-25.69812</td><td>-30.791197</td><td> </td></tr><tr><td>0.1</td><td>112.445855</td><td>108.177395</td><td>102.579509</td><td>95.384179</td><td>86.396863</td><td>75.206226</td><td>61.200302</td><td>44.511365</td><td>27.603038</td><td>13.116663</td><td>0.853254</td><td>-9.609617</td><td>-18.315011</td><td>-25.317822</td><td>-30.657122</td><td> </td></tr><tr><td>0.05</td><td>129.953349</td><td>126.729465</td><td>122.16493</td><td>115.888176</td><td>107.735583</td><td>97.599944</td><td>84.78044</td><td>67.007035</td><td>45.133323</td><td>25.293443</td><td>8.703572</td><td>-5.123796</td><td>-16.206876</td><td>-24.614329</td><td>-30.421939</td><td> </td></tr><tr><td>0</td><td>146.979281</td><td>145.477655</td><td>143.182354</td><td>139.720174</td><td>134.892754</td><td>128.593272</td><td>119.228637</td><td>104.230568</td><td>81.016758</td><td>53.376624</td><td>27.161422</td><td>5.354242</td><td>-11.477492</td><td>-23.316319</td><td>-30.26605</td><td> </td></tr><tr><td>x (mm)</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr></tbody></table>

1

There are 1 answers

0
John Bofarull Guix On

I have applied griddata and fit to the supplied data. poly23 is not the best choice to fit a surface to the supplied data, let me explain:

1.- This is the supplied data

clear all;close all;clc

% supplied data
E=[30.002332    21.985427   6.810482    -15.670808  -45.233394  -77.215051  -105.258626 -125.69229  -137.533424 -144.608218 -149.37894  -153.029304 -155.689815 -157.477955 -158.626949 
30.232465   24.087844   14.620048   1.72655 -14.792426  -35.152992  -59.469883  -84.288 -102.159215 -114.172775 -123.557279 -130.950597 -136.22158  -139.785929 -142.188687 
30.421325   24.932531   17.444529   7.892998    -3.856977   -18.014886  -34.99118   -54.76071   -73.12193   -87.497601  -98.824193  -108.060712 -114.987903 -120.253359 -124.356373 
30.551303   25.391767   18.870906   10.957517   1.538053    -9.535194   -22.598697  -38.389555  -55.208053  -69.556258  -81.254268  -90.739807  -98.322417  -104.256711 -108.853733 
30.664703   25.675715   19.70439    12.733737   4.693012    -4.564309   -15.382383  -28.781825  -44.015781  -57.405663  -68.654996  -78.136226  -85.96381   -92.262205  -97.271558  
30.727753   25.865955   20.238259   13.853267   6.664413    -1.448761   -10.800537  -22.615818  -36.367379  -48.848877  -59.549314  -68.920612  -76.813046  -83.32022   -88.600393  
30.865921   26.241471   21.290271   16.08672    10.626372   4.839985    -1.602854   -9.43494    -18.83834   -28.636958  -37.691591  -45.92364   -53.263184  -59.60791   -64.797286  
31.095974   26.462957   21.68939    16.805136   11.820302   6.696608    1.18386 -5.121618   -12.593724  -20.872655  -28.902156  -36.190138  -42.81756   -48.711318  -53.733812  
31.46129    26.783809   22.050232   17.24325    12.414941   7.549917    2.463171    -3.126318   -9.525282   -16.772883  -24.024533  -30.735935  -36.907371  -42.495141  -47.386621  
31.84872    27.13964    22.399963   17.609472   12.824883   8.054302    3.167199    -2.022925   -7.798272   -14.333423  -20.98601   -27.322197  -33.20454   -38.422392  -43.441491  
32.321379   27.611153   22.830246   18.00384    13.186564   8.407782    3.614684    -1.377083   -6.778505   -12.763999  -18.950497  -24.996769  -30.700952  -36.002519  -40.845001  
32.912865   28.117376   23.297908   18.414747   13.541529   8.720016    3.953985    -0.893617   -6.030829   -11.646948  -17.480042  -23.272051  -28.818368  -34.05723   -38.898901  
33.461235   28.733026   23.846096   18.900341   13.945926   9.043626    4.247023    -0.554529   -5.54091    -10.874341  -16.437732  -22.017734  -27.450488  -32.671967  -37.55842   
34.20239    29.399207   24.450979   19.429789   14.378361   9.384043    4.50818 -0.228657   -5.110888   -10.256221  -15.598685  -20.988768  -26.283234  -31.452038  -36.351057  
34.914372   30.186026   25.182228   20.081931   14.90649    9.757508    4.793411    -0.022121   -4.818618   -9.801554   -14.977042  -20.209359  -25.40338   -30.537892  -35.491473  
35.805782   31.056782   26.042754   20.849744   15.526359   10.206612   5.079032    0.217373    -4.533031   -9.394064   -14.424973  -19.520352  -24.601559  -29.643549  -34.578382  
36.912236   32.230447   27.190092   21.88521    16.388134   10.852426   5.512241    0.53729 -4.252576   -9.060047   -13.988674  -18.990227  -23.997652  -28.971069  -33.911535  
38.220177   33.55963    28.522922   23.132328   17.438377   11.652987   6.043032    0.901   -3.941164   -8.721107   -13.565417  -18.470008  -23.400995  -28.283206  -33.172001  
40.089435   35.460059   30.362062   24.861205   18.933028   12.805265   6.809413    1.39481 -3.583199   -8.390298   -13.200262  -18.057954  -22.938035  -27.768679  -32.61952   
42.604155   38.034489   32.852205   27.179704   21.024509   14.456797   7.936568    2.129503    -3.092501   -7.988163   -12.808929  -17.635859  -22.475901  -27.255258  -32.039299  
46.740509   42.104713   36.736597   30.755343   24.224614   17.087908   9.853802    3.360219    -2.293161   -7.426018   -12.358482  -17.254878  -22.122863  -26.910174  -31.65453   
53.63405    48.823341   43.145538   36.706073   29.56244    21.689267   13.405102   5.735263    -0.786028   -6.417941   -11.659605  -16.769755  -21.760135  -26.617262  -31.321544  
66.719783   61.669457   55.479065   48.279934   40.173712   31.232975   21.372923   11.406692   2.961089    -3.87916    -10.044617  -15.840246  -21.29497   -26.408778  -31.159668  
81.066195   75.939181   69.61686    62.097845   53.400235   43.453173   31.99206    19.510149   8.697597    0.08383 -7.513168   -14.397559  -20.598789  -26.139851  -31.007816  
88.630566   83.616297   77.408061   69.893348   60.994658   50.53292    38.266849   24.550308   12.460448   2.685077    -5.844277   -13.434216  -20.125472  -25.947463  -30.897252  
98.70275    93.957875   87.989331   80.562783   71.487536   60.477972   47.235774   32.081579   18.171011   6.62184 -3.316554   -11.987794  -19.434567  -25.69812   -30.791197  
112.445855  108.177395  102.579509  95.384179   86.396863   75.206226   61.200302   44.511365   27.603038   13.116663   0.853254    -9.609617   -18.315011  -25.317822  -30.657122  
129.953349  126.729465  122.16493   115.888176  107.735583  97.599944   84.78044    67.007035   45.133323   25.293443   8.703572    -5.123796   -16.206876  -24.614329  -30.421939  
146.979281  145.477655  143.182354  139.720174  134.892754  128.593272  119.228637  104.230568  81.016758   53.376624   27.161422   5.354242    -11.477492  -23.316319  -30.26605];

I have removed the 1st column from left hand side that doesn't seem to match the screenshot you have supplied.

and this is supplied data with surf

[sz2 sz1]=size(E)
x_range=[-floor(sz1/2):1:floor(sz1/2)];
y_range=[-floor(sz2/2):1:floor(sz2/2)];
[X,Y,Z]=meshgrid(x_range,y_range,0);

figure(1)
ax1=gca
hs1=surf(ax1,X,Y,E)

hs1.EdgeColor='none'
xlabel('X');ylabel('Y');
grid on
title('surf(data)')

enter image description here

direct surf does not add points, the coloured surface is rendering, one can check the amount of points generated with surf with hs1 the handle to this surf output

hs1 = 
  Surface with properties:

       EdgeColor: 'none'
       LineStyle: '-'
       FaceColor: 'flat'
    FaceLighting: 'flat'
       FaceAlpha: 1
           XData: [29×15 double]
           YData: [29×15 double]
           ZData: [29×15 double]
           CData: [29×15 double]

29x15 we just get what we give.

2.- In MATLAB the default command to fit a surface to 3D data is griddata

Applied here

% define finer grid
dx=.01
nx=(x_range(end)+1-(x_range(1)-1))/dx
x_range2=linspace(x_range(1)-1,x_range(end)+1,nx);
y_range2=linspace(y_range(1)-1,y_range(end)+1,nx);
[xq,yq,zq]=meshgrid(x_range2,y_range2,0);

% yq=linspace(y_range(1)-1,y_range(end)+1,nx);
E_range=linspace(min(E,[],'all'),max(E,[],'all'),nx);
% 

Eq=griddata(X,Y,E,xq,yq);
% Eq = griddata(x_range,y_range,E_range,E,xq,yq,zq);

figure(2)
ax2=gca
plot3(ax2,X,Y,E,'ro')
hold on
hs2=surf(ax2,xq,yq,Eq)

hs2.EdgeColor='none'
xlabel('X');ylabel('Y');
grid on
title('griddata(data)')

enter image description here

Now the handle hs2 from this surf does contain all the additional points generated when fitting a surface to the 29X15 (435) points.

Check

hs2 = 
  Surface with properties:

       EdgeColor: 'none'
       LineStyle: '-'
       FaceColor: 'flat'
    FaceLighting: 'flat'
       FaceAlpha: 1
           XData: [1600×1600 double]
           YData: [1600×1600 double]
           ZData: [1600×1600 double]
           CData: [1600×1600 double]

4.- Depending upon what version of MATLAB being used one can also use command fit to the purpose of fitting a surface to 3D points.

4.1.- fit option poly11 uses a simple linear polynomial curve f1_poly11(x,y) = p00 + p10*x + p01*y

x1=X(:); 
y1=Y(:); 
E1=E(:);

% 'poly11' Linear polynomial curve
%      f1_poly11(x,y) = p00 + p10*x + p01*y
f1_poly11 = fit([x1 y1],E1,"poly11")
figure(3)
plot(f1_poly11,[x1 y1],E1)
title('E fit with poly11')
% poly coefficients available here
f1_poly11.p00
f1_poly11.p10
f1_poly11.p01

enter image description here

as expected linear approximation is not best fit for the supplied points.

4.2.- linear interpolation does quite a good job though

f1_linint = fit([x1 y1],E1,"linearinterp")
figure(4)
plot(f1_linint,[x1 y1],E1)
title('E fit with linearinterp')
% poly coefficients available here
f1_linint.p

enter image description here

4.3.- option cubicinterp is a piecewise cubic interpolation

f1_cbint = fit([x1 y1],E1,"cubicinterp")
figure(5)
plot(f1_cbint,[x1 y1],E1)
title('E fit with cubicinterp')
% poly coefficients available here
f1_cbint.p

enter image description here

4.4.- option lowess is a local linear regression

f1_low = fit([x1 y1],E1,"lowess")
figure(6)
plot(f1_low,[x1 y1],E1)
title('E fit with lowess')
% poly coefficients available here
f1_low.p.Degree
f1_low.p.Lambda

enter image description here

again this regression is not as good as expected, is it?

4.5.- and poly23 is a similar approximation that you have used with nlinfit using the following expression :

f1_poly23(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p21*x^2*y + p12*x*y^2 + p03*y^3

MATLAB returns a confidence interval, always appreciated Coefficients with 95% confidence bounds.

f1_poly23 = fit([x1 y1],E1,"poly23")
figure(7)
plot(f1_poly23,[x1 y1],E1)
title('E fit with poly23')
% poly coefficients available yere
f1_poly23.p00
f1_poly23.p10
f1_poly23.p01
f1_poly23.p20
f1_poly23.p11
f1_poly23.p02
f1_poly23.p21
f1_poly23.p12
f1_poly23.p03

enter image description here

5.- So griddata is quite good at fitting curves.

I'd like to mention that since

hs2.XData
hs2.YData
hs2.ZData

already contains all the points of the approximating surface, do you really need the polynomial expression?

It may be easier and faster to generate the surface, and then whatever your coding is about, just read and process data with the stored points.

Additional comment

There is an improved version of griddata called gridfit by John D'Errico available here

https://uk.mathworks.com/matlabcentral/fileexchange/8998-surface-fitting-using-gridfit?s_tid=srchtitle_surface%20fitting_2

If you find this answer useful would you please be so kind to consider clicking on the accepted answer?

Thanks