# How does one get polynomial features like in python but for MatLab?

10 views (last 30 days)
Brando Miranda on 16 Oct 2017
Answered: Steven Lord on 12 Jan 2018
Is there code that gets the polynomial features of a vector like in:
e.g. for 1D 1,x,x^2 for degree 2. Ideally like the link I posted.
Ideally, is there no built in function in matlab that does this for me?
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Answers (2)

Sanjana Ramakrishnan on 19 Oct 2017
Edited: Walter Roberson on 11 Jan 2018
There is not a direct way of creating a polynomial matrix in MATLAB. Refer the below link for information on polynomial matrices:
However, you can create a vector of polynomial coefficients in MATLAB to represent a polynomial: https://www.mathworks.com/help/matlab/math/create-and-evaluate-polynomials.html
You can then append the vectors vertically to form a polynomial matrix
##### 1 CommentShow -1 older commentsHide -1 older comments
Brando Miranda on 11 Jan 2018
what about fitting polynomials?

Sign in to comment.

Steven Lord on 12 Jan 2018
For one variable, I think you want the vander function.
For multiple variables, use the x2fx function from Statistics and Machine Learning Toolbox. If you want terms with a degree greater than 2 (like x1.^2.*x2, with a degree of 2+1 = 3) you'd have to build the model input rather than using one of the predefined options like 'quadratic'. I believe there are some discussions on Answers and some files on the File Exchange for generating all combinations of N numbers that add up to a particular value that you could use to help you build the model input in that case.
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Categories

Find more on Polynomials in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!