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

  • Thread starter Thread starter swartzism
  • Start date Start date
  • Tags Tags
    Matlab Polynomial
AI Thread Summary
The discussion revolves around creating a symbolic polynomial in MATLAB, specifically of the form X(k+1) - X(k-d) - X(k-d-1) - ... - 1, using given values for d and k. The user initially shares their code, which successfully generates terms but fails to produce the desired polynomial output. The expected polynomial for k=5 and d=3 is X^6 - X^2 - X - 1, while the code only outputs X^6 - 1. After some adjustments, the user indicates they have resolved the issue and offers to share the corrected code. The thread highlights common challenges in symbolic computation with MATLAB and the iterative process of debugging code to achieve the desired mathematical expression.
swartzism
Messages
103
Reaction score
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
After some tinkering, I got it to work. If you would like to see the code, let me know.
 

Similar threads

Back
Top