least squares for fitting experimetal data

I am an undergrad in chemistry and do not have a strong background in coding. Anyways my question is I have to to make a lot of linear fits form experimental data and I was wondering if there is an easy way to do this using least squares (which I do understand. At least more than coding) I am trying to avoid using the basic fit option to enhance my repertoire.

 Accepted Answer

Star Strider
Star Strider on 6 Mar 2016
Edited: Star Strider on 6 Mar 2016
There are three straightforward ways to do linear least-squares fitting in MATLAB:
1. The mldivide,\ operator (or function),
2. The polyfit function,
3. The fminsearch function (although you have to code the objective function for it)
Admittedly, fminsearch is serious overkill for a linear problem, but I want to be certain I cover all the options. It is quite useful for small nonlinear problems (fewer than about 6 parameters) that you will eventually encounter in Chemistry.
EDIT There are a number of other options in the Statistics and Machine Learning Toolbox, but assuming you’re interested in only the functions available in core MATLAB, they’re all I covered here.

More Answers (0)

Categories

Find more on Chemistry in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!