1 Aralık 2012 Cumartesi

MATLAB

Some basic MATLAB codes 

        Polyfit(Polynomial curve fitting)

Syntax
p=ployfit(x,y,n)
[p,S]=ployfit(x,y,n)
[p,S,mu]=ployfit(x,y,n)


p = polyfit(x,y,n) finds the coefficients of a polynomial p(x) of degree n that fits the data,p(x(i)) to y(i), in a least squares sense.
Example
x = (0: 0.1: 2.5)';
y = erf(x);
p = polyfit(x,y,6) 
The coefficients in the approximating polynomial of degree 6 are

p = 0.0084   -0.0983     0.4217     -0.7435    0.1471    1.1064   0.0004

There are seven coefficients, and the polynomial is


p=

Ref: http://www.mathworks.com/help/matlab/ref/polyfit.html

         Roots (Polynomial roots)

Syntax
r = roots(c)
r = roots(c) returns a column vector whose elements are the roots of the polynomial c.
Example
The polynomial s3 – 6s2 – 72s – 27 is represented in MATLAB software as
p = [1 -6 -72 -27]
The roots of this polynomial are returned in a column vector by
r = roots(p)
r =    12.1229
        -5.7345
                -0.3884

Hiç yorum yok:

Yorum Gönder