How to Generate Symbolic Polynomial in MATLAB with Given Parameters?

In summary, the conversation discusses the issue of producing a symbolic polynomial in MATLAB. The desired polynomial is given a d and k, and the code provided is meant to generate the polynomial. However, there is an issue with the code, as it is only producing X6-1 instead of the desired X6-X2-X-1. After some tinkering, the issue is resolved and the correct polynomial is produced.
  • #1
swartzism
103
0
I am trying to get MATLAB to be able to produce a symbolic polynomial and am having some issues. The polynomial I would like it to produce is given a d and k,

X(k+1)-X(k-d)-X(k-d-1)-...-1

What I have so far is

Code:
k = 5;
d = 3;
syms X;

i = 0;
while (k-(d+i) >= 0)
    terms(i+1) = k-(d+i);
    i = i+1;
end

for j=1:i
    poly = X^(k+1);
    poly = inline(poly - X^(terms(j)));
end

This code is the example where k = 5, d = 3. The first while loop generates the terms of the polynomial, the second is meant to generate the polynomial, but it is not working.

In this example, the desired polynomial is

X6-X2-X-1

What the code is producing is

X6-1

Any ideas on what I can do to produce the correct polynomial?

Thanks in advance.
 
Physics news on Phys.org
  • #2
After some tinkering, I got it to work. If you would like to see the code, let me know.
 

Related to How to Generate Symbolic Polynomial in MATLAB with Given Parameters?

1. What is a MATLAB polynomial problem?

A MATLAB polynomial problem refers to a mathematical problem that involves the manipulation and analysis of polynomials using the MATLAB software. It can involve tasks such as finding roots, solving equations, and performing operations on polynomials.

2. How do I input a polynomial in MATLAB?

To input a polynomial in MATLAB, you can use the poly function. For example, if your polynomial is 2x^3 + 3x^2 + 5x + 1, you would input it as poly([2 3 5 1]). This will create a vector of coefficients that represents the polynomial.

3. How do I find the roots of a polynomial in MATLAB?

To find the roots of a polynomial in MATLAB, you can use the roots function. This will return a vector containing all the roots of the polynomial. For example, if your polynomial is represented by the vector p, you would use roots(p) to find its roots.

4. Can I solve polynomial equations in MATLAB?

Yes, you can solve polynomial equations in MATLAB using the roots function. This function can handle equations of any degree and will return all the solutions to the equation. However, it is important to note that this function may not work for all types of equations, such as those with complex roots.

5. How can I graph a polynomial in MATLAB?

To graph a polynomial in MATLAB, you can use the plot function. First, create a vector of x-values, then use the polyval function to evaluate the polynomial at those x-values. Finally, use the plot function to create a graph of the polynomial. You can also add a title, labels, and customize the appearance of the graph using various options in MATLAB.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
641
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
Back
Top