You are on page 1of 6

Introduction:

Curve fitting is the process of constructing a curve, or mathematical function, that has the best fit to a series of datapoints, possibly subject to constraints. Curve fitting can involve either interpolation, where an exact fit to the data is required, or smoothing, in which a "smooth" function is constructed that approximately fits the data. A related topic is regression analysis, which focuses more on questions of statistical inference such as how much uncertainty is present in a curve that is fit to data observed with random errors. Fitted curves can be used as an aid for data visualization, to infer values of a function where no data are available, and to summarize the relationships among two or more variables.

Purpose of curve fitting :

Types of curve fits :


Two main categories, 1.Non linear curve fits: Nonlinear regression is a form of regression analysis in which observational data are modeled by a function which is a nonlinear combination of the model parameters and depends on one or more independent variables. The data are fitted by a method of successive approximations. 2.Least square curve fit :

The five least square curve fit available are discussed below : Linear :

Matlab command :

Polynomial :

Exponential :

Matlab command :

Logarithmic :

Matlab command :

Power:

Matlab command :

Linear Regression in MATLAB Fitting a least-squares linear regression is easily accomplished in MATLAB using the backslash operator: '\'. In linear algebra, matrices may by multiplied like this: output = input * coefficient

Linear curve fitting with MATLABs Built-in Functions


POLYFIT Fit polynomial to data. POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of degree N that fits the data, P(X(I))~=Y(I) , in a least-squares sense. \ Backslash or matrix left division. If A is a square matrix, A\B is roughly the same as inv(A)*B , except it is computed in a different way.
p = polyfit(x,y,n) [p,S] = polyfit(x,y,n)

where the p is polynomial coefficient and a structure S for use with polyval to obtain error estimates or predictions http://www.mathworks.com/help/matlab/ref/polyfit.html
POLYVAL Evaluates a polynomial at given points
y = polyval(p,x) [y,delta] = polyval(p,x,S) y = polyval(p,x,[],mu) [y,delta] = polyval(p,x,S,mu) where the optional output structure S generated by polyfit to generate error estimates delta. delta is an estimate of the standard deviation of the error in predicting a future observation at x by p(x).

http://www.mathworks.com/help/matlab/ref/polyval.html http://peart.ucs.indiana.edu/docs/tutorials/matlab/node10.html https://docs.google.com/viewer?a=v&q=cache:RL3wXj6t9L8J:web.itu.edu.tr/~sertele/dersler/matlab/ders08.p df+regression+curve+fitting+matlab&hl=en&pid=bl&srcid=ADGEESiv7JRnjYd0ELXnKKrwQgZ1397k5Dc wY4EVyVZkaLPAhaUy28UBr_XcV6x37s9CPK1muYvdDzxQbPq5LZ_77aQHU4Nboe_K30hcvN6i_ufeoOEk8CWM8ILCMdZvx1Av4lDhD9H&sig= AHIEtbSIZmCtaGukECyAm2aYr5MjTBmVfw

Fitting to a line with Matlab


1.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; from mA. >> plot(x,y,'o'); %Plot data with circles >> title('Verifying Ohms Law'); >> xlabel('Volts'); >> ylabel('Current (Amps)'); %Convert to amps

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

3.Hit the right arrow at the bottom of the box.

The figure now looks as shown.

Since the slope is about 0.01, the resistance is about 100 ohms. 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

You might also like