Polynomial PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Scilab/Advanced Level/Polynomials

From Spoken Tutorials Wiki

< Scilab

Title of script: Polynomials in Scilab

Author: Anuradha Amrutkar

Keywords: scilab, polynomials

Visual Clue Narration


Welcome to the spoken tutorial on Polynomials in
Scilab.

By using Scilab you can create polynomials, find


1 st Slide their roots and perform operations on them such as
addition, subtraction, multiplication, division,
simplification, etc.

Please open Scilab Console window to practise this


Scilab Console
tutorial
Scilab Console and type

-->x = poly(0, 'x') Let us create a polynomial in x with one root at


x = zero. It can be done using the following command
x

Type

-->p = 1+x+2*x^2 This variable x can now be used to define another


p =
2 polynomial in x using
1 + x + 2x

Now type We can directly define a polynomial by specifying


all its roots. For example Let us create a polynomial
-->p1 = poly([3 2], 'x') p1 having roots 3 and 2, and x being the symbolic
or
variable. The polynomial is p1 = 6−5x+x^2.In the
above polynomial p1 it is observed that the third
type

-->p1 = poly([3 2], 'x', 'r')


parameter, when supplied, may be 'r' or 'roots' in
which case the first parameter is a vector
p1 = containing the roots of the polynomial.
2

6 - 5x + x

Now we will create a polynomial p2 having


coefficients 6,−5,1 assuming the symbolic variable
Now type as x again. The polynomial is p2 = 6−5x+x^2.

-->p2 = poly([6 -5 1], 'x', 'c') In the above polynomial p2 which is same as p1, it
p2 = is observed that, the third parameter, when
2
supplied, may be 'c' or 'coeff' in which case the first
parameter is a vector containing the coefficients of
6 - 5x + x the polynomial, starting from the constant as the
first element and power of the symbolic variable
increasing by one for each element in the vector.

Thus, the polynomial with two roots is a polynomial


of order two. Similarly, a polynomial with three
coefficients is also a polynomial of order two.
Switch Back to 2 nd Slide
When the third parameter is not supplied, it
defaults to 'r' or 'roots'.

Type
It is possible to perform a number of operations on
-->p1 polynomials, such as, find its roots, add, subtract,
p1 =
2
multiply, divide and simplify.

Recall p1 by typing
6 - 5x + x

-->roots(p1)

ans =
the roots of p1 can be obtained as:
2.
3.

type

-->p2
p2 = Also recall p2
2
6 - 5x + x

type
Now add the two polynomials p1 and p2 and store
-->p3 = p1 + p2
p3 = the result in the polynomial p3.
2
Subtraction can be performed in a similar way.
12 - 10x + 2x

type
Product of two polynomials is also a polynomial, and
-->p4 = p1 * p2
is calculated using the multiplication operator (*).
p4 =
2 3 4

36 - 60x + 37x - 10x + x

type

-->q1 = 1+x
q1 =
We will define another polynomial say q1 as

1+x

type

-->q2 = 1+2*x+x^2
q2 = and q2 as
2
1 + 2x + x

type Dividing a polynomial with another polynomial is


done as shown
-->q = q1 / q2
q =
1
-----

1+x

type

-->q3 = 1+3*x+2*x^2
q3 =
2
also let us define another polynomial say q3 as
1 + 3x + 2x

type

-->q1/q3
ans =
and divide q1 by q3 as

0.5
-------

0.5 + x

type The derivative of the polynomial p1 can be obtained


using the derivat command
-->derivat(p1)
ans =

- 5 + 2x

type

-->derivat(p1*p2) Also we can find derivative of p1*p2


ans =

− 60 + 74x − 30x^2 + 4x^3


type

-->coeff(p1)
ans = The coefficients of the polynomial p1 can be found
out using the coeff command as
6. - 5. 1.

type

-->horner(p1,0)
ans =

To evaluate a polynomial p1 at ' 0 ' or at set of


6. values ' [0 1 2] ' the horner command is used.

type

-->horner(p1,[0 1 2])
ans =

6. 2. 0.

We will now see how to find factors of a polynomial


type
For this purpose the factors() command is used.
-->p3
p3 = This command performs numeric real factorization.
2

Let us see an example to illustrate this concept.


12 - 10x + 2x
Let us Recall p3 which was p1+p2 and

type

-->factors(p3)
ans =
ans(1) find its factors using the factors() command
- 2 + x
ans(2)
- 3 + x

Type

-->q3 Also let us recall q3 and find its factors


q3 =
2
1 + 3x + 2x

type

-->factors(q3)
ans =
ans(1)
0.5 + x
ans(2)
1 + x

Another important feature that scilab provides is


partial fraction decomposition of the linear system.
type Let us see an example

--> s = %s;
Let us declare 's' as symbolic variable with the
command

Please note that defining symbolic variable using


the above command works only for variable s and z.

Slide 3 But the command 'poly' used at the start of the


tutorial to define a polynomial in x, works for any
variable.

Scilab Console and type

Now we will define a transfer function with


numerator and denominator abbreviated as 'num'
-->num =1; and 'den' respectively.
-->den =s^2+3*s+2;

Type

-->tf=num/den
Let us now define a variable say 'tf' in the form of
fraction
tf =
1 and
---------
2
2 + 3s + s
type

-->pfe=pfss(tf)
pfe =
pfe(1)
1 perform the partial fraction decomposition
-----
1 + s operation on 'tf' using the 'pfss() command as
pfe(2)
- 1
-----
2 + s

type
Let us retrieve the original transfer function by
-->orig = pfe(1)+pfe(2) adding the output obtained from the pfss()
orig = command

1
--------- which is exactly same as the transfer function we
2 defined using the num and den variables.
2 + 3s + s

Let us now discuss how to find poles and zeros of a


transfer function.

Consider a Second Order Transfer Function with no


zeros of the form

dividing numerator and denominator by d2 gives


Slide 4

Equating the RHS of the above equation to the


standard Second Order System

We obtain
Slide 5
and

which help to solve for ωn and ζ

In Scilab 'trfmod()' with option 'f' gives

Numerator

and Denominator ωn and ζ

Consider an example

we get this equal to

Slide 6
This gives the natural frequency

ωn = 2

and damping ratio

Scilab Console type

-->g = 5/(2*s^2+3*s+8)

This brings us to the end of spoken tutorial on


Polynomials in Scilab.
In this tutorial we have learnt how to create
polynomials in scilab and how to perform various
operations on those polynomials. There are many
other functions in Scilab which will be covered in
other spoken tutorials. Keep watching the Scilab
links.

The Spoken Tutorials are part of the Talk to a


Teacher project, supported by the National Mission
on Education through ICT abbreviated as NMEICT
given by MHRD government of India. More
Slide 7
information on the same is available at this
websitehttp://spoken-tutorial.org/NMEICT-Intro.
Thanks for joining us. This is Anuradha Amrutkar
signing off. Goodbye.

Contributors and Content Editors


Anuradha, Belur, Kannan, NiketaTrivedi, Sengupta

Retrieved from "http://spoken-tutorial.org/wiki/index.php/Scilab/Advanced_Level


/Polynomials"

This page was last modified on 29 November 2010, at 08:36.

You might also like