# Curve Fitting Exercise in MATLAB

## Summary

In this activity, students program using MATLAB to compare the fit of several models to an experimental data set. The activity is designed to teach students with limited MATLAB experience how to write code to fit models to data, and to understand basic theory on how to compare models. While a data set from a gene delivery nanoparticle is presented in the activity, an instructor can substitute a data set more appropriate to any discipline.

Used this activity? Share your experiences and modifications

## Learning Goals

By the end of the activity, the students should be able to:
1. Fit a curve to data and determining goodness of fit
2. Use the function fminsearch in MATLAB to minimize a function
3. Understand vocabulary used to describe model fits to data
4. Use simple theory about model fitting to select the best model for a data set

Students write their own MATLAB code (with hints), which teaches them a skill that allows them to fit models to data sets later in their education and careers with great flexibility.

## Context for Use

This activity is targeted at freshmen or sophomore undergraduates who have not taken a full class dedicated to programming with MATLAB, but have received some instruction or tutorial on MATLAB programming. For example, it was the third MATLAB lab in my introductory bioengineering course for sophomores. Specifically, the students will need to know how to
1. Write and run MATLAB script files
2. perform matrix algebra using MATLAB.
3. Look up and call functions in MATLAB.
4. Use the plot function
If the students have also learned to input and output data and use flow control functions, the activity could be modified to make use of these skills, but they are not required for this activity.
This activity requires no discipline specific knowledge; while the data set involves a pharmaceutical/bioengineering example, all information needed to understand it is provided, and it would be appropriate for any students with interest in medicine. It would also be fairly simple for an instructor to exchange in a new data set and discipline-specific learning objectives to better integrate the activity into their curriculum. It should even be possible to use the same data provided, but change the units and description, as long as the data description would be consistent with the exponential approach model used.
The assignment should take students less than three hours and could be appropriate as a lab activity or as a homework assignment.

## Description and Teaching Materials

The activity allows the students to fit four models with 2,3, or 4 parameters to a data set and compare the goodness of fit while considering Occam's razor, and then to compare the predictive power of the four models. The detailed activity is provided in the "Curve fitting exercise in MATLAB" supporting material
Student Handout for Curve Fitting Excercise in MATLAB (Microsoft Word 2007 (.docx) 29kB Oct5 16)

## Assessment

the students are asked to complete a worksheet or write up that includes key plots and answers to questions. The plots can be used to assess learning objectives 1 and 2 while the answers can be used to assess objectives 3 and 4.