### Fitting With Multiple Independent Variables

#### Defining the Fitting Function

Start the nonlinear curve fitter by selecting Analysis:Nonlinear Curve Fit. If you are in the basic mode you will see a More button. Click on it to proceed to the advanced mode. Next select Function:New. If you receive the following attention message: "Do you want to end the fitting session with function...", click Yes. You are now in the Define New Function dialog box. To define the function, enter or select the following for the listed fields:

 Name: 3DGauss (Optional) User-Defined Param. Names: checked Type: User-Defined Parameter Names: a,xc,xs,yc,ys Independent Var.: x,y Dependent Var.: z Definition: GaussX = exp( - (x-xc)^2 / (2*xs^2) ); GaussY = exp( - (y-yc)^2 / (2*ys^2) ); z = a * GaussX * GaussY; Form: Y-Script After entering all this information, click the Save button to save your input to a function definition file (*.FDF) in Origin's FitFunc subfolder. Click on Figure 1 to see how it should all look. Users who do not want to manually define the fitting function can download the *.FDF. To get it up and running, be sure to read the instructions provided on the download page!

#### Assign the Datasets

Select Action:Dataset from the list of menus in the fitter or click on the icon to proceed to the Select Dataset dialog box. Assign the datasets as follows:

 z   Dep data1_c y   Indep data1_b x   Indep data1_a

If you are unfamiliar with this process, follow the steps below:

1. Select the z Dep variable.
2. Click on data1_c in the Available Datasets list.
3. Click the Assign button.

=> Along with assigning data1_c this will automatically assign data1_a to the x Indep variable and create a plot of data1_c versus data1_a.

4. Select the y Indep variable.
5. Click on data1_b in the Available Datasets list.
6. Click the Assign button.

#### Initialize the Parameters

Select Action:Fit or click on the icon to proceed to the Fitting Session dialog box. Once there you will find the five parameters listed in the order in which they were defined. Scrolling will be necessary to see the parameter called ys. Parameter a corresponds to the peak amplitude. Parameters xc and yc represent the center of the peak along the x and y dimensions respectively. Parameters xs and ys represent the width (sigma) of the peak along the x and y dimensions respectively. Initialize each parameter by entering the appropriate value (as shown in the list below) in the Value text boxes provided next to each parameter name.

 a = 90 xc = 25 xs = 5 yc = 25 ys = 5

#### One Final Step Before Fitting

In order to illustrate that Origin's curve fitter did indeed fit multiple independent variables, a comparison between surface plots of the original data and the fit data is necessary. Since this is the case, the fit data should be forced to use the same X values as the original data. To make this happen, select Scripts:After Fit from the fitter's menus and then the Same X as Fitting Data radio button from the Fit Curve group. Finally, if you want to save this setting to the *.FDF file, select Function:Edit and click the Save button again.

#### Iterate and Click Done

Return to the Fitting Session dialog box by selecting Action:Fit again. Rather than attempting to get the best fit possible, simply click the 1 Iter. button once or twice. Doing so will provide results that are accurate enough to illustrate a successful multiple independent variable fit. Each iteration will take approximately 1 minute to complete due to the complicated nature of the fitting function.

Once the iterations are complete, click the Done button to end the fitting session and exit the fitter. Upon clicking Done the fit data will be appended to Data1 in a column called B1(Y). The graph will also update to contain a results label. However, the graph is not important to the lesson and can therefore be deleted or hidden. To delete or hide it, simply click on the X in the upper right hand corner of the graph window, then choose either Delete or Hide.

#### Convert to Matrix Regular and Plot3D

Before you can compare the fit data to the original data, all that's left to do is convert the fit data into a matrix and plot it. Follow the steps below to do so.

1. Change the column designation of B1 from Y to Z.

To do that, activate Data1, right-click on B1(Y) and select Set As:Z. Alternatively, follow either of the other two methods outlined in Change the Z Column Designation to Y. B1(Y) then changes to B1(Z).

2. Move C(Y) so that B1(Z) is positioned adjacent to the associated X and Y data.

To do that, select C(Y) and then Column:Move to Last. Alternatively, you can delete C(Y) since it is not needed for the purposes of this lesson. To do so, right-click on C(Y) of the Data1 worksheet and select Delete.

3. Convert the XYZ data to a matrix.

Click on B1(Z) and select Edit:Convert to Matrix:Regular. The data is quickly converted into a matrix.

4. Plot the new matrix.

With the newly created matrix set as the active window, select Plot3D:3D Color Map Surface.

5. Rescale one Z axis

The Z scale of the original 3D color map surface plot goes from 0 to 110, whereas the Z scale of the 3D color map surface plot for the fit data goes from 0 to 100. To ensure that both plots are identically displayed, equate the Z axis scales for both graphs.

To do this, select the 3D color map surface plot of the fit data and then Format:Axes:Z Axis. Next, select the Scale tab and enter 110 in the "To" text box. Click OK to apply the change and close the dialog box. Finally, activate the original plot and confirm that its Z axis To value is indeed 110. If not, change it to 110 as well.

#### Compare

 Upon observing both of your graphs you should notice that the 3D color map surface plot of the fit data is clearly smoother than that of the of the original data. If you were unable to complete the example or the graph of your fit data does not appear to be any different than the graph of the raw data, click on Figure 2 to take a look at some typical results. Otherwise, this completes this Example 1. If you are interested in another real world example of multiple independent variable fitting in Origin, continue to the next page. Figure 2

page 1
page 2
page 3