Main Content

Surface Fitting to Franke Data

The Curve Fitter app provides some example data generated from Franke's bivariate test function. This data is suitable for trying various fit settings in the Curve Fitter app. Use the data to create, compare, and export surface fits.

  1. At the MATLAB®command line, load thefrankedata set. The variablesx,y, andzappear in the workspace.

    loadfranke

    The example data is generated from Franke's bivariate test function, with added noise and scaling, to create suitable data for trying various fit settings in the Curve Fitter app. For details on the Franke function, see[1].

  2. Divide the data into fitting and validation data.

    xv = x(200:293);yv = y(200:293);ZV = Z(200:293);x = x(1:199);y = y(1:199);Z = Z(1:199);

  3. Fit a surface using the example data.

    1. Open the Curve Fitter app.

      curveFitter
      或者,在Appstab, in theMath, Statistics and Optimizationgroup, clickCurve Fitter.

    2. In the Curve Fitter app, select the data variables. On theCurve Fittertab, in theDatasection, clickSelect Data. In the Select Fitting Data dialog box, specifyxas theX Datavariable,yas theY Datavariable, andzas theZ Datavariable.

      Select Fitting Data dialog box with Franke fitting data

      Alternatively, you can specify the data variables when you usecurveFitterto open the Curve Fitter app and create a default fit (curveFitter(x,y,z)).

    The Curve Fitter app plots the data points as you select variables. When you selectx,y, andz, the app automatically creates a default surface fit. The default fit is an interpolating surface that passes through the data points.

    Default Curve Fitter interpolant surface fitted to Franke data

  4. Try a Lowess fit type. On theCurve Fittertab, in the适合类型section, click the arrow to open the gallery. ClickLowessin theSmoothinggroup.

    适合类型画廊,清单洛斯和其他t型车ypes

    The Curve Fitter app creates a local smoothing regression fit.

  5. Try altering the fit settings. In theFit Optionspane, change theSpan (%)value to10.

    By reducing the span from the default to 10% of the total number of data points, you produce a surface that follows the data more closely. The span defines the neighboring data points the app uses to determine each smoothed value.

    Plot of Lowess fit with reduced span

  6. In theTable Of Fitspane, change theFit nametoSmoothing regression.

  7. Use the validation data to check that your surface is a good model. In other words, compare the surface against data not used for fitting.

    On theCurve Fittertab, in theDatasection, clickValidation Data. In the Select Validation Data dialog box, select the validation variables in the drop-down lists forX Data,Y Data, andZ Data:xv,yv, andzv.

    Review your selected validation data in the plots and the validation statistics (SSE and RMSE) in theResultsandTable Of Fitspanes.

    洛斯的情节符合验证数据点代表resented by unfilled circles

  8. Create another fit by making a copy of the current surface fit. On theCurve Fittertab, in theFilesection, click复制. Alternatively, right-click the fit in theTable Of Fitspane, and then select复制"Smoothing regression".

    The app creates a new fit figure with the same fit settings, data, and validation data. It also adds a new row to the table of fits at the bottom.

  9. Change the fit type and name of the new fit. On theCurve Fittertab, in the适合类型section, click the arrow to open the gallery. ClickPolynomialin theRegression Modelsgroup.

    In theTable Of Fitspane, change theFit nametoPolynomial.

  10. In theFit Optionspane, change theX DegreeandY Degreevalues to3,在两个维度上拟合立方多项式。

  11. Look at the scales on the x and y axes, and read the warning message in theResultspane.

    Equation is badly conditioned. Remove repeated data points or try centering and scaling.

    In theFit Optionspane, select theCenter and scale复选框以归一化并校正X和Y中尺度的较大差异。

    Fit options for the polynomial fit, including the centering and scaling of the data

    Normalizing the surface fit removes the warning message from theResultspane.

  12. Look at theResultspane. You can view the:

    • Model equation

    • Values of the estimated coefficients

    • Goodness-of-fit statistics

    • Goodness of validation statistics

    Linear model Poly33: f(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y... + p02*y^2 + p30*x^3 + p21*x^2*y + p12*x*y^2 + p03*y^3 where x is normalized by mean 1977 and std 866.5 and where y is normalized by mean 0.4932 and std 0.29 Coefficients (with 95% confidence bounds): p00 = 0.4359 (0.3974, 0.4743) p10 = -0.1375 (-0.194, -0.08104) p01 = -0.4274 (-0.4843, -0.3706) p20 = 0.0161 (-0.007035, 0.03923) p11 = 0.07158 (0.05091, 0.09225) p02 = -0.03668 (-0.06005, -0.01332) p30 = 0.02081 (-0.005475, 0.04709) p21 = 0.02432 (0.0012, 0.04745) p12 = -0.03949 (-0.06287, -0.01611) p03 = 0.1185 (0.09164, 0.1453) Goodness of fit: SSE: 4.125 R-square: 0.776 Adjusted R-square: 0.7653 RMSE: 0.1477 Goodness of validation: SSE : 2.26745 RMSE : 0.155312

  13. To export this fit information to the workspace, clickExportand selectExport to Workspacein theExportsection of theCurve Fittertab. Executing this command also exports other information such as the number of observations and parameters, residuals, and the fitted model.

    You can treat the fitted model as a function to make predictions or evaluate the surface at values of X and Y. For details seeExporting a Fit to the Workspace.

  14. Display the residuals plot to check the distribution of points relative to the surface. On theCurve Fittertab, in theVisualizationsection, clickResiduals Plot.

    Plot of residuals for the polynomial fit

  15. Right-click the residuals plot to selectGo to X-Z view. The X-Z view is not required, but the view makes it easier to see to remove outliers.

  16. To remove outliers, click the Exclude outliers buttonin the axes toolbar.

    When you move the mouse cursor to the plot, it changes to a cross-hair to show you are in outlier selection mode.

    1. Click a point that you want to exclude in the surface plot or residuals plot. Alternatively, click and drag to define a rectangle and remove all enclosed points.

      The plots display removed points as red crosses.

      Plot of residuals with some excluded data points

    2. If you haveAutoselected in theFitsection of theCurve Fittertab, the app refits the surface without the removed point. If you haveManualselected instead, you can clickFit重新表面。

    3. 要返回图中的旋转模式,请单击“排除离群”按钮again.

  17. Compare your fits side-by-side. Click the Document Actions arrow located to the far right of the fit figure tabs. Select theTile Alloption and specify a 1-by-2 layout.

    Side-by-side display of the smooth regression and polynomial fits

  18. Review the information in theTable Of Fitspane. Compare the goodness-of-fit statistics for all fits in your session to determine which is best.

  19. To save your interactive surface fitting session, clickSavein theFilesection of theCurve Fittertab. You can save and reopen sessions to access multiple fits. The session file contains all the fits and variables in your session.

  20. After interactively creating and comparing fits, you can generate MATLAB code for each fit in your Curve Fitter app session. On theCurve Fittertab, in theExportsection, clickExportand selectGenerate Code.

    曲线Fitter应用程序从您的会话中生成代码,并在MATLAB编辑器中显示文件。该文件包括当前选择的拟合及其在您的会话中打开的图。

  21. Save the file with the default namecreateFit.m.

  22. You can recreate your fit and its plots by calling the file from the command line (with your original data or new data as input arguments). In this case, your original variables still appear in the workspace.

    • Highlight and evaluate the first line of the file (excluding the wordfunction). Either right-click and selectEvaluate Selection in Command Window, pressF9, or copy and paste the following code to the command line.

      [fitresult,gof] = createFit(x,y,z,xv,yv,zv)

    • The function creates a figure window for the fit you selected in your session. Observe that the polynomial fit figure shows both the surface and residuals plots that you created interactively in the Curve Fitter app.

    • If you want, you can use the generated code as a starting point to change the surface fits and plots to fit your needs. For a list of methods you can use, seesfit.

参考

[1] Franke, Richard. “Scattered Data Interpolation: Tests of Some Methods.”Mathematics of Computation38, no. 157 (January 1, 1982): 181–200. https://doi.org/10.1090/S0025-5718-1982-0637296-4.

相关话题