[Scilab-users] Polynomic regression

Dang, Christophe Christophe.Dang at sidel.com
Wed Jul 2 10:20:21 CEST 2014


Hello, 

> De : Amalia Susana
> Envoyé : mardi 1 juillet 2014 21:20
>
> Yes I need the inverse function of Cs(k).
> [...]
> how can I obtain a polynomic regression taking values from a real number interval?
>
> Or may I give the computer the pairs (x,y) ?

Yes indeed, you need to feed your script with the values.

Generally speaking, if you have a column vector x and a column vector y,
and for a 3rd degree polynomial,
you define

X = [x.^3, x.^2, x, ones(x)]

and then perform

A = X\y

the matrix division performs the solution of a linear system or, in our case, the regression using the least squares method, see
http://help.scilab.org/docs/5.5.0/en_US/backslash.html

A is the vector containing the coefficients of the polynomial.

There are then two ways to define the function.
As this is a polynomial, you can just do :

P = [%s^3, %s^2, %s, 1]*A

and compute the "theoretical" values by

yth = horner(P, x)

or you can define a general function, something like

function [y] = P(A, x)
    y = [x.^3, x.^2, x, ones(x)]*A
endfunction

This is a general presentation.
In your case, you might exchange x and y (if I understood well),
have line vectors instead of column
(you can then transpose the vectors with ', or use the other matrix divider /)
use a different degree for your polynomial, etc.

Now if you want to group three analytical functions, for three intervals, inside one single Scilab function, an efficient way to do this is:

function [y] = P(A1, A2, A3, x)
    boolean1 = (x < x1); // x1 is the lower threshold value
    boolean2 = (x >= x1)&(x < x2); // x2 is the upper threshold value
    boolean3 = (x >= x2);
    y = zeros(x); // sets the size for y
    y(boolean1) = P1(A1, x(boolean1));
    y(boolean2) = P2(A2, x(boolean2));
    y(boolean3) = P3(A3, x(boolean3));
    // alternative: y(boolean1) = horner(P1, x(boolean1)); etc.
endfunction

where P1, P2 and P3 are the three polynomials.

Does this help?

-- 
Christophe Dang Ngoc Chan
Mechanical calculation engineer

______________________________________________________________________

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
______________________________________________________________________



More information about the users mailing list