The Least-Squares Fit function (
) defines a least-squares fit of a function to the input data, which can be a file, a local table, or a result table. The function can be a general mathematical function with parameterized expressions, such as
a+b*cos(x1)+c*sin(x2)+x3+x4^2. The default
Function name is
lsq1_fun1. The least-squares fit can have multiple function outputs. If a second output is added, it will become
lsq1_fun2, a third will become
lsq1_fun3, and so on.
Click the Fit Parameters button (
) to fix the data to the parameters of the function. The computed parameter values from the least-squares fit appear in the
Parameters section below. Click the
Plot button (
) to plot the function using the parameters from the least-squares fit. The input data also appears as green squares so that you can see how close those data points are to the fitted function.
Select a Data source —
File,
Local table, or
Result table to define the data source for the least-square fit.
If you select File (the default), enter the complete network path and name of the data file in the
Filename field, or click
Browse to select a text or data file with data in the
Interpolation Data dialog box. You can import data files with comma-separated, semicolon-separated, space-separated, and tab-separated data. You can also click the downward arrow beside the
Browse button and choose
Browse From (
) to open the fullscreen
Select File window. Click the downward arrow for the
Location menu (
) to choose
Show in Auxiliary Data (
) to move to the row for this file in the
Auxiliary Data window,
Copy Location (
), and (if you have copied a file location)
Paste Location (
). Also choose a decimal separator from the
Decimal separator list:
Point (the default) or
Comma. Click
Import (
) to import the data into the model; otherwise, COMSOL Multiphysics references the data on your file system. Click
Export to save the least-squares data to a file and reference from there instead of including it in the model. Click the
Discard button to delete the imported least-squares data from the model. Click the
Refresh button (
)to ensure that the file is reread when needed.
If you select Local table, enter the function argument values in
Column 1 and the corresponding function values in
Column 2. Click the
Add Argument Column button (
) below the table to add a column for a new function argument. Click the
Add Value Column button (
) to add a column for a new function value. Use the
Delete Column (
),
Delete Row (
), and
Clear Table (
) buttons as desired to edit the table. Use the
Load from File (
) and
Save to File (
) buttons to load or save data to or from the table. You can also click the downward arrow beside the
Load from File button and choose
Load From (
) to open the fullscreen
Select File window.
If you select Result table, choose the table to use from the
Result table list.
When selecting a row in the Settings column, you can edit the name of the function or argument in the
Name field underneath and also provide a unit in the
Unit field. For the function, also enter the definition of the function in the
Expression field, such as
a1*x1+a0 for a linear function with two parameters,
a0 and
a1.
In the table in this section, add the parameters that are used in the function defined under Data Column Settings above and that should be computed using a least-squares fit. Type the name in the
Parameter column. The original values in the
Value column (default: 0) will be updated when you click the
Fit Parameters button, using the values from the least-squares fit. Use the buttons underneath the table to move or delete parameters and to load or save the parameters and their values to or from a file.