0% found this document useful (0 votes)
44 views

Linear Regression With Matlab

This document provides instructions for performing linear regression with Matlab. It describes entering voltage and current data, plotting the data, and using the Basic Fitting tool to perform linear regression. The slope of the fitted line corresponds to a resistance of 100 ohms, matching Ohm's Law. The correlation coefficient near 1 indicates a good fit to the linear model.

Uploaded by

Simon Martinez
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Linear Regression With Matlab

This document provides instructions for performing linear regression with Matlab. It describes entering voltage and current data, plotting the data, and using the Basic Fitting tool to perform linear regression. The slope of the fitted line corresponds to a resistance of 100 ohms, matching Ohm's Law. The correlation coefficient near 1 indicates a good fit to the linear model.

Uploaded by

Simon Martinez
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Linear Regression with Matlab

http://www.swarthmore.edu/NatSci/echeeve1/Ref/Matlab/CurveFit/L...

Fitting to a line with Matlab


Back First enter some data, and plot it.
>> >> >> >> >> >> x=[0 2.6 5.1 7.4 9.6 7.8 4.8 2.6 0.1]; y=[-0.3 23.5 51.9 70.1 98.2 82.9 46.0 28.6 4.8]/1000; plot(x,y,'o'); %Plot data with circles title('Verifying Ohms Law'); xlabel('Volts'); ylabel('Current (Amps)'); %Convert to amps from mA.

Go to Tools->Basic Fitting and set dialog box as below

1 de 5

14/09/2011 12:04 p.m.

Linear Regression with Matlab

http://www.swarthmore.edu/NatSci/echeeve1/Ref/Matlab/CurveFit/L...

Hit the right arrow at the bottom of the box.

2 de 5

14/09/2011 12:04 p.m.

Linear Regression with Matlab

http://www.swarthmore.edu/NatSci/echeeve1/Ref/Matlab/CurveFit/L...

The figure now looks as shown.

3 de 5

14/09/2011 12:04 p.m.

Linear Regression with Matlab

http://www.swarthmore.edu/NatSci/echeeve1/Ref/Matlab/CurveFit/L...

Since the slope is about 0.01, the resistance is about 100 ohms. It is also possible to use Matlab do the curve-fit and then calculate the correlation coefficient. In the following code "p" contains coefficients of linear, or first order, fit (slope=m=p(1)=0.0100, intercept=b=p(2)=0.006).
>> p=polyfit(x,y,1) p = 0.0100 0.0006 >> R=corrcoef(x,y); >> R(1,2) ans = 0.9961

A correlation coefficient with a magnitude near 1 (as in this case) represents a good fit. As the fit gets worse, the correlation coefficient approaches zero.

email me with any comments on how to improve the information on this page (either presentation or content), or to let me know if you had any particular difficulties with this lab. You may use any portion of this document for your lab report, but be sure to reference it. Back

4 de 5

14/09/2011 12:04 p.m.

Linear Regression with Matlab

http://www.swarthmore.edu/NatSci/echeeve1/Ref/Matlab/CurveFit/L...

5 de 5

14/09/2011 12:04 p.m.

You might also like