How to Generate Symbolic Polynomial in MATLAB with Given Parameters?

  • Context: MATLAB 
  • Thread starter Thread starter swartzism
  • Start date Start date
  • Tags Tags
    Matlab Polynomial
Click For Summary
SUMMARY

The discussion focuses on generating a symbolic polynomial in MATLAB using specified parameters d and k. The user initially attempts to create the polynomial X(k+1) - X(k-d) - X(k-d-1) - ... - 1 but encounters issues with their code. After troubleshooting, the correct polynomial output for k = 5 and d = 3 is confirmed as X^6 - X^2 - X - 1. The user successfully resolves the problem and offers to share the working code.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of symbolic computation in MATLAB
  • Knowledge of polynomial expressions and their manipulation
  • Basic programming concepts such as loops and conditionals
NEXT STEPS
  • Explore MATLAB's symbolic toolbox for advanced polynomial manipulation
  • Learn about MATLAB's inline function and its usage in symbolic expressions
  • Investigate the creation of dynamic polynomial expressions based on variable parameters
  • Study examples of symbolic computation in MATLAB to enhance problem-solving skills
USEFUL FOR

Mathematics students, engineers, and developers working with MATLAB who need to generate and manipulate symbolic polynomials for various applications.

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

  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
0
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K