tailieunhanh - APPLIED NUMERICAL METHODS USING MATLAB phần 4

thứ chức năng [, err, yi] = polyfits (x, y, N, xi, r)% x, y: các vectơ hàng dữ liệu N cặp%: thứ tự của đa thức (= 0)% r: đảo ngược trọng yếu tố mảng kích thước tương tự như chiều dài = y M (x); x = x (:); y = y (:);% Thực hiện tất cả các vectơ cột nếu nargin == 4 nếu chiều dài (xi) == M, r = xi; xi = x% Với tham số đầu vào (x, y, N, r) khác r = 1;% | 146 INTERPOLATION AND CURVE FITTING function th err yi polyfits x y N xi r x y the row vectors of data pairs N the order of polynomial 0 r reverse weighting factor array of the same dimension as y M length x x x y y Make all column vectors if nargin 4 if length xi M r xi xi x With input argument x y N r else r 1 With input argument x y N xi end elseif nargin 3 xi x r 1 With input argument x y N end A N 1 ones M 1 for n N -1 1 A n A n 1 . x end Eq. if length r M for m 1 M A m A m r m y m y m r m end Eq. end th A y Eq. or ye polyval th x err norm y - ye norm y estimated y values error yi polyval th xi do_polyfit load x xy1 1 y xy1 2 x i sort x y y i sort the data for plotting xi min x 0 100 100 max x - min x intermediate points for i 1 4 th err yi polyfits x y 2 i - 1 xi err LS subplot 220 i plot x y k xi yi b end xy1. dat Example . Polynomial Curve Fit by LS Least Squares . Suppose we have an ASCII data file containing a set of data pairs xk yk k 0 6 in two columns and we must fit these data into polynomials of degree 1 3 5 and 7. x -3 -2 -1 y 0 1 2 3 We make the MATLAB program which uses the routine polyfits to do this job and plot the results together with the given data CURVE FITTING 147 8 6 4 2 0 -2 -4 _ _ _ . -4 -2 0 2 4 d Polynomial of degree 7 Figure Polynomial curve fitting by the LS Least-Squares method. points as depicted in Fig. . We can observe the polynomial wiggle that the oscillation of the fitting curve between the data points becomes more pronounced with higher degree. Example . Curve Fitting by WLS Weighted Least Squares . Most experimental data have some absolute and or relative error bounds that are not uniform for all data. If we know the error bounds for each data we may give each data a weight inversely proportional to the size of its error bound

TỪ KHÓA LIÊN QUAN