File Exchange

image thumbnail

Symbolic Polynomial Manipulation

version 1.19 (52.5 KB) by

Symbolic polynomial manipulation as an exercise in OOP

7 Ratings



View License

This toolbox is a very simple polynomial manipulation package.
I originally wrote it some years ago as a means of learning how to work with objects in Matlab. When I decided to publish this package, I completely rewrote it from scratch just this week, as the old one had some bugs in it.

Why publish this at all? Because I think writing such a tool is a marvelous way to learn about OOP and the use of classes in Matlab. A second reason is that this toolbox is actually of use to me on occasion, whenever I need to manipulate simple polynomials in one or several variables. If, as is the case with me and you don't own the symbolic toolbox, you may find it of interest too. I have included the functions orthpoly and gaussquadrule, as neat applications of the sympoly tools.

I've also put in a helper document that discusses things I felt important in writing a toolbox like this.

If you wish to use these tools, they are quite easy to use. A few quick examples:

% This creates 3 sympoly objects in your
% workspace: x, y, z.
sympoly x y z

% Add 1 to x, put the result in p.
p = x+1

% arbitrary expressions
q = (x-1)^3 + x*y*z - (x+1)*(z-1)

There are many other examples in the ReadMe file, some involving arrays of sympolys, as well as many more.

Whatever use you do find for this toolbox, have fun with it. I did. I even get some use from it occasionally.

If by some amazing chance you do find any bugs, please e-mail me.

Comments and Ratings (10)

Mark Mikofski

Mark Mikofski (view profile)

Hi John! Happy to see you are still cranking and contributing your genius to the MATLAB community. Are you still experimenting with Python anymore? FYI: Python has a great symbolic toolbox called SymPy ( similar to MATLAB and Maple, completely free, and available with the Anaconda Scientific Python Distribution from Continuum Analytics ( Also you should seriously get on GitHub ( Take Care!

John D'Errico

John D'Errico (view profile)

I think the issue is…

>> sympoly x y
>> P = x + x*y + 3*x^2 + 2*y^2 + 5*x*y^2;

Now, if I want to extract terms with y in them, terms finds nothing, because the default behavior is to find terms that match exactly y. x*y fails to match, as does y^2. So terms returns a zero.

>> terms(P,y,'extract')
ans =

However, we can change the behavior to be a bit more flexible, allowing it to find any term with y to the first power in it.

>> terms(P,y,'extract',0)
ans =

Note that y^2 will still never match the pattern I've specified.


Micah (view profile)

It seems like there is an error when trying to extract a coefficient of say x^2. It always provides zero. Any one else see this?

Shaohan Hu


emilio Arnieri

Meghana Ranade

really helpful.. :)

Oh-ig Kwoun

Excellent job! Thank you !!!



Flag as a toolbox


Final bug fix for polyerrorprop

Repaired a bug when substitutions are done into a constant sympoly.

Version 2: added sympoly toolbox issues doc, plus HTML files, along with several new functions.

Version 1.2 - Fixed a bug in subsasgn to make deal & repmat work properly. Added diag and adjoint capability, plus sympoly2poly. Added author, date and release number to the ReadMe doc.

Version 1.1: Repair disp bug - extraneous "*"
Version 1.2: Repaired a synthetic division bug

Fixed a minor bug in the display of long expressions (too many *'s)

MATLAB Release
MATLAB 7.0.1 (R14SP1)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today