Professional Documents
Culture Documents
SCILAB Exercise- 3
Polynomials
p(x)=a0x0+a1x1+a2x2+…+anxn
where:
an – real numbers (an ∈ R), representing the coefficients of the polynomial
x – symbolic variable of the polynomial
n – natural numbers (an ∈ N), representing the exponents of the
polynomial
The syntax of the Scilab poly() function is:
p = poly(data, 'var', 'options')
where:
--> x=poly(0,'x')
x =
x
-->
Polynomial definition:
--> p=-2-x+x^2
p =
2
-2 -x +x
-->
To check if a variable is a polynomial or not, we can use the Scilab
function typeof(). If true, the return of the function will be the
string 'polynomial'.
3
The poly() function is also used to define transfer functions for dynamic
systems. The approach is to define first the symbolic variable and second
the rational function, which represents the transfer function.
4
Image: Scilab plot for a 3rd order polynomial
To find the roots of the polynomial p2, we use the following Scilab
instruction:
--> r=roots(p2)
r =
-0.6276878
1.2029662
0.5675787
-->
The roots are stored in the vector r but as complex numbers, which have
the imaginary part equal to zero. To check the type of numbers of the
roots we can use the Scilab function isreal().
--> isreal(r)
ans =
F
-->
As you can see, the return of the check is False which means that the
vector is made up of complex numbers. To convert them into real
numbers we can use the Scilab function real().
--> r=real(r)
5
r =
-0.6276878
1.2029662
0.5675787
-->
If we apply the same type check, this time we’ll get a different result:
--> isreal(r)
ans =
T
-->
As you can see, the roots returned with the function roots() fit with the x-
coordinates where the plot crosses the horizontal axis. This mean that the
roots where correctly calculated.