Download presentation
Presentation is loading. Please wait.
Published byProsper Owens Modified over 9 years ago
2
Numerical Operations S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: Polynomial Manipulations
3
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Polynomials 2 Polynomial Topics n Entering Polynomials Entering Polynomials n Roots Roots n Multiplication Multiplication n Evaluation Evaluation n Curve Fitting Curve Fitting
4
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Polynomials 3 Entering Polynomials n In Matlab, a polynomial is represented by a row vector of it’s coefficients in descending order n Is entered as: » p=[1 -12 0 25 116] n Zero term coefficients MUST be included n For example, the polynomial
5
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Polynomials 4 Roots To find the roots of a polynomial use roots n Roots are always column vectors » p=[1 -12 0 25 116]; » r=roots(p) r = 11.7473 2.7028 -1.2251 + 1.4672i -1.2251 - 1.4672i
6
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Polynomials 5 Mutliplication Use the conv (convolution) command to evaluate the product of two polynomials: » a=[1 2 3 4];b=[1 4 9 16]; » c=conv(a,b) c = 1 6 20 50 75 84 64
7
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Polynomials 6 Evaluation polyval is used to evaluate the polynomial p(x) between -1 and 3 » x=linspace(-1,3);% 100 data points » p=[1 4 -7 -10];% Coefficients » v=polyval(p,x);% Evaluate » plot(x,v); » title('x^3 +4x^2 -7x -10'); » xlabel('x');
8
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Polynomials 7 Evaluation Plot
9
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Polynomials 8 Curve Fitting polyfit implements a least squares curve fitting algorithm » x=[0:0.1:1]; » y=[-0.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2]; » n=2; % Order of Fit » p=polyfit(x,y,n)
10
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Polynomials 9 Polyfit Polyfit returns coefficients of curve fit solution » p = polyfit(x,y,n) p = -9.8108 20.1293 -0.0317
11
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Polynomials 10 Compare Solutions » xi=linspace(0,1,100); » z=polyval(p,xi); » plot(x,y,'-o',xi,z,':'); » xlabel('x'); » ylabel('y=f(x)'); » title('Second Order Curve Fitting'); n Least Mean Squared (LMS) Error Minimization
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.