POLYNOMIALS Representation of Polynomial n is degree of

advertisement
POLYNOMIALS
Representation of Polynomial
n is degree of polynomials
Example:
Degree of 2
Degree of 0
Representation of Polynomial s in SCILAB
Two way of declaring polynomials in SCILAB
i. Using %s
Example :
ii. Using function poly
Example :
Usage of function poly
There are 3 methods to use function poly to create polynomials:
i. Declaring variable as a symbolic variable
Example 1:
s=poly (0,’s’)
s1=s^2+4*s+5
Example 2:
x=poly (0,’x’)
x1=x^4- 21*x^3 + 43*x^2 + 10*x +4
ii. By using polynomial coefficients
 Polynomials can be represented by row vector in which elements are the coefficients
 Must include all coefficient , even if 0
Example:
a) p = 10 + 4x
p=poly ([10 4], ‘x’,’c’)
b) q=2x3 -5x + 7
q=poly ([7 -5 0 2],’x’,’c’)
iii. By using roots of polynomials
SCILAB can be calculate the polynomial coefficients from the roots of polynomial (which
are the values of argument for which the polynomial is equal to zero)
Example:
roots = -3, +2
x= -3
or
x=2
0 = x +3
0=x-2
0 = (x + 3)(x +2)
f(x) = x2 + x - 6
r = poly([ -3 2],’x’)
Answer:
r = -6 + x + x2
SCILAB can be computing the roots of a function.
r = roots(p)
where :
p : row vector with polynomial coefficients in decreasing degree order
r : column vector with roots of polynomial
Example:
f(x) = x2 – 2x -3
p = [1 -2 -3]
r = roots(p)
Answer:
r=
3.0000
-1.0000
Values of Polynomials
SCILAB can be compute the value of a polynomial at point x using a function, which is sometimes more
convenient. This function below is derived from Horner’s method:
polyval (p,x)
p : vector with coefficients of the polynomial
x ; number, variable or expression
Example:
polyval([5 6 -7 3],2)
Arithmetic Operation of Polynomials
i. Added or subtracted
Example:
f1 (x) + f2(x)
f1(x) = 3x2 + 15x – 40
f2(x) = 5x + 20
SCILAB code:
x=poly (0,’x’)
f1= 3*x^2 + 15*x – 40
f2 = 5*x +20
f1 + f2
ii. Multiplied
Example:
f = (2x2 +x – 3)*(x + 1)
SCILAB code:
x = poly (0,’x’)
f = (2*x^2+x-3)*(x+1)
iii. Divided
Example:
f = (x2-9x-10) / (x+1)
SCILAB code:
x = poly (0,’x’)
f = (x^2 -9*x -10)/(x+1)
Useful function for Polynomials
i. Function coeff
- To get the coefficients of matrix polynomials
Example:
B = x^2 + 4*x +5
C = coeff(B)
ii. Function derivat
- To get the rational matrix derivative
Example:
D = 2*x^3 + 4*x^2 – 5
E = derivat(D)
Download