Download presentation
Presentation is loading. Please wait.
1
MATLAB Polynomials
2
Introduction Polynomials x2+2x-7 x4+3x3-15x2-2x+9
In MATLAB polynomials are created by row vector i.e. s4+3s3-15s2-2s+9 >>p=[ ]; 3x3-9 >>q=[ ] %write the coefficients of every term Polynomial evaluation : polyval(c,s) Exp: Evaluate the value of polynomial y=2s2+3s+4 at s=1, -3 >>y=[ ]; >>s=1; >>value=polyval(y, s) >>value = 9
3
Polynomials Evaluation
Similarly >>s=-3; >>value=polyval(y, s) >>value = 13 OR >>s=[1 -3]; >> value=polyval(y, s) value = >> value=polyval(y,[1 -3])
4
Roots of Polynomials Roots of polynomials: roots(p) >>p=[1 3 2]; % p=s2+3s+2 >>r=roots(p) r = Try this: find the roots of s4+3s3-15s2-2s+9=0
5
Polynomials mathematics
Addition >>a=[ ]; %s2+2s+1 >>b=[ ]; % s3+s+1 >>c=a+b %s3+s2+3s+6 Subtraction >>a=[ ]; %s3+2 >>b=[ ]; %s+7 >>c=b-a %-s3+s+5 c=
6
Polynomials mathematics
Multiplication : Multiplication is done by convolution operation . Sytnax z= conv(x, y) >>a=[1 2 ]; %s+2 >>b=[ ]; % s2+4s+8 >>c=conv(a, b) % s3+6s2+16s+16 c= Try this: find the product of (s+3),(s+6) & (s+2). Hint: two at a time Division : Division is done by deconvolution operation. Syntax is [z, r]=deconv(x, y) Where x=divident vector y=divisor vector z=Quotients vector r=remainders vector
7
Polynomials mathematics
>>a=[ ]; %a=s3+6s2+16s+16 >>b=[ ]; %b=s2+4s+8 >>[c, r]=deconv(a, b) c= 2 r= Try this: divide s2-1 by s+1
8
Formulation of Polynomials
Making polynomial from given roots: >>r=[-1 -2]; %Roots of polynomial are -1 & -2 >>p=poly(r); %p=s2+3s+2 p= 3 2 Characteristic Polynomial/Equation of matrix ‘A”: =det(sI-A) >>A=[0 1; 2 3]; >>p=poly(A) %p= determinant (sI-A) p= %p=s2-3s-2
9
Polynomials Differentiation & Integration
Polynomial differentiation : syntax is dydx=polyder(y) >>y=[ ]; %y=s4+4s3+8s2+16 >>dydx=polyder(y) %dydx=4s3+12s2+16s dydx= Polynomial integration : syntax is x=polyint (y, k) %k=constant of integration OR x=polyint(y) %k=0 >>y=[ ]; %y=4s3+12s2+16s+1 >>x=polyint(y,3) %x=s4+4s3+8s2+s+3 x= (this is k)
10
Polynomials Curve fitting
In case a set of points are known in terms of vectors x & y, then a polynomial can be formed that fits the given points. Syntax is c=polyfit(x, y, k) %k is degree of polynomial Ex: Find a polynomial of degree 2 to fit the following data Sol: >>x=[ ]; >>y=[ ]; >>c=polyfit(x, y, 2) %2nd degree polynomial c= >>c=polyfit(x, y, 3) %3rd degree polynomial c = X 1 2 4 Y 6 20 100
11
Polynomials Curve fitting
Ex: Find a polynomial of degree 1 to fit the following data Sol: >>current=[ ]; >>voltage=[ ]; >>resistance=polyfit(current, voltage, 1) resistance= i.e. Voltage = 10x Current Current 10 15 20 25 30 voltage 100 150 200 250 300
12
Polynomials Evaluation with matrix arguments
Ex: Evaluate the matrix polynomial X2+X+2, given that the square matrix X= Sol: >>A=[1 1 2]; %A= X2+X+2I >>X=[2 3; 4 5]; >>Z=polyvalm(A,X) %poly+val(evaluate)+m(matix) Z=
13
Hello
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.