Search code examples
scilabpolynomials

enter polynomial in scilab interactively


How can be done that the user enters a polynomial to define a transfer function,

I ve using

numT=input('Enter poly numerator:');

But this only gets a Double type variable instead of a polynomial type, Been trying as well

->n=poly([denT],'s','coeff');    

but this says >Invalid factor.

Thanks


Solution

  • The input command supports two types of input: numeric and a string. For this purpose, it's convenient to accept a string and evaluate with eval:

    x = poly(0, "x")    // seed for polynomial
    str = input("Enter a polynomial of x: ", "string")
    p = eval(str)  
    disp(p)             // confirmation for the user
    

    For example, the user can enter (3*x^3-2)^2 and the expression shown back is

           3    6  
    4 - 12x + 9x