< Introduction to Chemical Engineering Processes
Introduction to MATLAB
Inserting and Manipulating Data in MATLAB
Importing Data from Excel
Performing Operations on Entire Data Sets
Graphing Data in MATLAB
Polynomial Regressions
MATLAB is able to do regressions up to very large polynomial orders, using the "polyfit" function. The syntax for this function is:
polyfit(XDATA, YDATA, Order)
The x data and y data must be in the form of arrays, which for the purposes of this application are simply comma-separated lists separated by brackets. For example, suppose you want to perform the same linear regression that had been performed in the "linear regression" section. The first step is to define the two variables:
>> XDATA = [1.1,1.9,3.0,3.8,5.3]; >> YDATA = [559.5,759.4,898.2,1116.3,1308.7];
Then just call polyfit with order '1' since we want a linear regression.
>> polyfit(XDATA, YDATA, 1) ans = 1.0e+002 * 1.77876628209900 3.91232582806103
The way to interpret this answer is that the first number is the slope of the line (1.778*10^2) and the second is the y-intercept (3.912*10^2).
Nonlinear Regressions (fminsearch)
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.