Sie sind auf Seite 1von 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.

1 st Slide

By using Scilab you can create polynomials, find their roots and perform operations on them such as addition, subtraction, multiplication, division, simplification, etc. Please open Scilab Console window to practise this tutorial

Scilab Console Scilab Console and type


-->x = poly(0, 'x') x = x

Let us create a polynomial in x with one root at zero. It can be done using the following command

Type
-->p = 1+x+2*x^2 p = 2 1 + x + 2x

This variable x can now be used to define another polynomial in x using

Now type
-->p1 = poly([3 2], 'x') or

We can directly dene a polynomial by specifying all its roots. For example Let us create a polynomial p1 having roots 3 and 2, and x being the symbolic variable. The polynomial is p1 = 65x+x^2.In the above polynomial p1 it is observed that the third

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

p1

= 2

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

6 - 5x + x Now we will create a polynomial p2 having coecients 6,5,1 assuming the symbolic variable as x again. The polynomial is p2 = 65x+x^2. In the above polynomial p2 which is same as p1, it is observed that, the third parameter, when supplied, may be 'c' or 'coeff' in which case the first parameter is a vector containing the coefficients of 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. When the third parameter is not supplied, it defaults to 'r' or 'roots'.

Now type
-->p2 = poly([6 -5 1], 'x', 'c') p2 = 2

6 - 5x + x

Switch Back to 2 nd Slide

Type
-->p1 p1 = 2

It is possible to perform a number of operations on polynomials, such as, find its roots, add, subtract, 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 = 2 6 - 5x + x

Also recall p2

type
-->p3 = p1 + p2 p3 = 2

Now add the two polynomials p1 and p2 and store the result in the polynomial p3. Subtraction can be performed in a similar way.

12 - 10x + 2x type
-->p4 = p1 * p2 p4 = 2 3 4

Product of two polynomials is also a polynomial, and is calculated using the multiplication operator (*).

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 = 2 1 + 2x + x

and q2 as

type
-->q = q1 / q2 q =

Dividing a polynomial with another polynomial is done as shown

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
-->derivat(p1) ans =

The derivative of the polynomial p1 can be obtained using the derivat command

- 5 + 2x type
-->derivat(p1*p2) ans =

Also we can find derivative of p1*p2

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 =

6.

To evaluate a polynomial p1 at ' 0 ' or at set of 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 For this purpose the factors() command is used.
-->p3 p3 = 2

type

This command performs numeric real factorization. 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) - 2 + x ans(2) - 3 + x

find its factors using the factors() command

Type
-->q3 q3 = 2

Also let us recall q3 and find its factors

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

type --> s = %s;

Another important feature that scilab provides is partial fraction decomposition of the linear system. Let us see an example 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' and 'den' respectively.

-->num =1; -->den =s^2+3*s+2;

Type
-->tf=num/den

Let us now define a variable say 'tf' in the form of fraction and
2

tf

= 1 --------2 + 3s + s

type
-->pfe=pfss(tf) pfe = pfe(1) 1 ----1 + s pfe(2) - 1 ----2 + s

perform the partial fraction decomposition operation on 'tf' using the 'pfss() command as

type
-->orig = pfe(1)+pfe(2) orig =

Let us retrieve the original transfer function by adding the output obtained from the pfss() command which is exactly same as the transfer function we defined using the num and den variables.

1 --------2 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

Slide 4

dividing numerator and denominator by d2 gives

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 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.

Slide 7

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.

Das könnte Ihnen auch gefallen