POLYNOMIALS
In MATLAB, a polynomial is represented by a vector. To create a polynomial in MATLAB, simply enter each coefficient of the polynomial into the vector in descending order. For instance, let's say you have the following polynomial: To enter this into MATLAB, just enter it as a vector in the following manner
x = [1 3 -15 -2 9]
x =
1 3 -15 -2 9
MATLAB can interpret a vector of length n+1 as an nth order polynomial. Thus, if your polynomial is missing any coefficients, you must enter zeros in the appropriate place in the vector. For example, would be represented in MATLAB as:
y = [1 0 0 0 1]
You can find the value of a polynomial using the polyval function. For example, to find the value of the above polynomial at s=2,
z = polyval([1 0 0 0 1],2)
z =
17
You can also extract the roots of a polynomial. This is useful when you have a high-order polynomial such as Finding the roots would be as easy as entering the following command;
roots([1 3 -15 -2 9])
ans =
-5.5745
2.5836
-0.7951
0.7860
Let's say you want to multiply two polynomials together. The product of two polynomials is found by taking the convolution of their coefficients. MATLAB's function conv that will do this for you.
x = [1 2];
y = [1 4 8];
z = conv(x,y)
z =
1 6 16 16
Dividing two polynomials is just as easy. The deconv function will return the remainder as well as the result. Let's divide z by y and see if we get x.
[xx, R] = deconv(z,y)
xx =
1 2
R =
0 0 0 0
As you can see, this is just the polynomial/vector x from before. If y had not gone into z evenly, the remainder vector would have been something other than zero.
Sunday, September 18, 2011
POLYNOMIALS
Labels:
Matlab Basics,
Polynomials
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment