# Data Model Building through Function Discovery

#### Summary

This activity introduces students to use data plots to obtain a mathematical function or "mathematical model" that describes the process that generated the data. The students become familiar with most common function types that often describe the physical phenomena. These include linear, power, and exponential functions.

## Learning Goals

At the end of this activity, students are expected to learn:

1. How to import data from Excel to MATLAB?

2. Mathematical relationships describing linear, power, and exponential functions.

3. The procedure to identify an underlying function describing a set of data.

4. How to generate scatter plots of data?

5. Use of first order polynomial fitting to determine the coefficients of underlying functions in the data.

## Context for Use

This activity is suitable for an undergraduate level (junior or senior) college course focused on using MATLAB for improving computational skills especially data modeling. Class size may be between 20 - 30 students. This is a classroom/lab activity. One lecture/lab session (80 to 120 minutes) is sufficient. The concepts can be reinforced through homework based on the material covered in class. To be successful, the students need to have basic skills in MATLAB including:

1. Working with Files, and MATLAB Help System
2. Numeric Arrays, and Element-by-Element Operations
3. MATLAB Functions including user-defined functions

## Description and Teaching Materials

In this activity, I introduce the students to the mathematical representation of three function types that are often used to describe physical phenomena. These include:

1.The linear function: y(x) = mx + b.

2. The power function: y(x) = b xm .

3. The exponential function: y(x) = b (10)mx

These functions give a straight line when plotted using a specific set of axis. The linear function gives straight line when plotted on rectilinear axis. Its slope is m and its intercept is b. The power function gives a straight line when plotted on log-log axis. The exponential function give a straight line when plotted on semilog plot whose y-axis is logarithmic. I ask the students to look for straight line on the plot because it will be easy to recognize and they will be able to easily tell whether the function will fit the data well. I demonstrate the following procedure to identify a function that describes a given set of data:

1. Import the data into MATLAB from an Excel spreadsheet.

2. Examine the scatter plot of the imported data near the origin. The exponential function can never pass through the origin unless it is trivial case of b=0. The linear function can pass through the origin only if b=0. The power function can pass through the origin only if m > 0.

3. Looking at the rectilinear plot of the data, if it forms a straight line, then the data can be represented by the linear function and we are done. Otherwise, if there is data at x = 0, then if y(0) = 0, try the power function. If y(0) is not equal to 0, try the exponential function. If data are not given for x = 0, proceed to step 4.

4. If a power function is suspected, plot the data using log-log scale. Only a power function will form a straight line on a log-log plot. If an exponential function is suspected, plot the data using semilog scales. The exponential function will form a straight line on semilog plot.

5. The log-log and semilog plots are only used to identify the function type, and not for finding coefficients b and m. This is because it is difficult to interpolate on log scales.

6. Find the values of b and m using MATLAB's polyfit function. The polyfit function finds the coefficients of a polynomial of specified degree n, that best fits the data in the least-square sense. The function is used to find a first-order polynomial that corresponds to a straight line

7. Use the polyfit to find the coefficients for the three function types as follows:

a. The Linear Function: The coefficients of a linear function are found by typing p = polyfit(x,y,1) in MATLAB. The first element of p will be coefficient m and the second element will be b.

b. The Power Function: The coefficients of power function are found by typing p = polyfit(log10(x), log10(y), 1). Again, the first element of p will be coefficient m and the second element will be log10(b).

c. The Exponential Function: The coefficients of exponential function are found by typing p = polyfit(x, log10(y), 1). The first element will be m, and the second element will be log10(b) from which b can be found.

## Teaching Notes and Tips

Before the class, instructor needs to make sure that they have excel spreadsheets of data representing the three function types. The data can be uploaded to a Blackboard course module before class or can be emailed to students to practice with during the class. The instructor can start with explaining and demonstrating the linear function. The students follow the instructor as they go through the three sets of data and develop MATLAB code to discover the underlying functions in the data.

## Assessment

I schedule programming tests as course assessments and give the students data files to discover underlying functions in the data. I also take short quizzes in Blackboard comprising true/false, multiple choice, and fill in the blank type questions to assess if students have gone over the required material, and have understood the concepts.

## References and Resources

Reference:

1. William J. Palm III, MATLAB for Engineering Applications, Fourth edition, McGraw-Hill Education, 2019.

Exponential_Data .xlsx (Excel 2007 (.xlsx) 9kB Aug25 19)

Linear_Data.xlsx (Excel 2007 (.xlsx) 8kB Aug25 19)

Power_Data.xlsx (Excel 2007 (.xlsx) 9kB Aug25 19)