Difference between revisions of "ApCoCoA-1:MatlabCoCoAPoly"
(Examples updated) |
m (→Methods) |
||
Line 55: | Line 55: | ||
* display: Is used by Matlab to print a CoCoAPoly to the command window. E.g. when a command is not terminated by a ';'. | * display: Is used by Matlab to print a CoCoAPoly to the command window. E.g. when a command is not terminated by a ';'. | ||
* end: returns the last coloumn or row of CoCoAPoly array | * end: returns the last coloumn or row of CoCoAPoly array | ||
− | * eq: Compares two polynomials. Returns 1 if all attributes are equal. Of polynomials are not equal 0 is returned. | + | * eq: Compares two polynomials. Returns 1 if all attributes are equal. Of polynomials are not equal 0 is returned. This function is called when using the '==' operator |
* get: get: Returns the attributes of a polynomial. Syntax: get(polyVar, 'Keyword'), where polyVar is a CoCoAPoly and 'Keyword' is one of the keywords listed in table 1. Additionaly the keyword 'String' can be used. This will return the polynomial as a string. | * get: get: Returns the attributes of a polynomial. Syntax: get(polyVar, 'Keyword'), where polyVar is a CoCoAPoly and 'Keyword' is one of the keywords listed in table 1. Additionaly the keyword 'String' can be used. This will return the polynomial as a string. | ||
* gt: ToDo: Implement based on ring ordering. Using LPP | * gt: ToDo: Implement based on ring ordering. Using LPP | ||
Line 61: | Line 61: | ||
* mpower: Returns the i-th power of a polynomial | * mpower: Returns the i-th power of a polynomial | ||
* mtimes: Multiplies two polynomials | * mtimes: Multiplies two polynomials | ||
− | * ne: returns NOT eq. | + | * ne: returns NOT eq. This function is called when using the '~=' operator |
* plus: Adds two polynomials | * plus: Adds two polynomials | ||
* subsasgn: Writes a polynomial to the (i,j) coordinate of a CoCoAPoly array | * subsasgn: Writes a polynomial to the (i,j) coordinate of a CoCoAPoly array |
Revision as of 11:45, 28 February 2008
Introduction
The CoCoAPoly class represents a polynomial over a given polynomial ring (See CoCoARing).
It is based on a representation of the terms by using the logarithm of the term. For example the polynomial x^2+2y+3xy+4 defined over the Ring Q[x,y] can be represented in a matrix of the following form:
coeff | power x | power y |
1 | 2 | 0 |
2 | 0 | 1 |
3 | 1 | 1 |
4 | 0 | 0 |
Constructor
The constructor for a CoCoAPoly can be used in one of the three different forms:
- CoCoAPoly('keyword1',value1,'keyword2','value2',...).
Available keywords are listed below:
Keyword | Description | Default |
Ring | A CoCoARing object | Q[x[1]] |
Terms | A term representing matrix as described above. Can also be the string 'One' or 'Zero'. This will generate the constant 1 or 0 polynomial. | [0 0] |
Table 1: Keywords for CoCoAPoly
- A string can be passed as a single argument. For example: CoCoAPoly('x^2+2y'). The string must hold the following conventions:
- Indeterminates: a-z
- + or - seperates two terms without blanks
- Coefficients are placed left to the indeterminate without blanks and without a '*' character.
- Note: The ring is build upon the found indeterminates over Q with a DegRevLex ordering.
- A real numeric value can be passed as a single argument. For example: CoCoAPoly(2). This will return a constant polynomial over Q[x[1]].
Attributes
- ring: A CoCoARing
- terms: a polynomial representing matrix as described above.
Methods
- display: Is used by Matlab to print a CoCoAPoly to the command window. E.g. when a command is not terminated by a ';'.
- end: returns the last coloumn or row of CoCoAPoly array
- eq: Compares two polynomials. Returns 1 if all attributes are equal. Of polynomials are not equal 0 is returned. This function is called when using the '==' operator
- get: get: Returns the attributes of a polynomial. Syntax: get(polyVar, 'Keyword'), where polyVar is a CoCoAPoly and 'Keyword' is one of the keywords listed in table 1. Additionaly the keyword 'String' can be used. This will return the polynomial as a string.
- gt: ToDo: Implement based on ring ordering. Using LPP
- minus: Subtract one polynomial from another
- mpower: Returns the i-th power of a polynomial
- mtimes: Multiplies two polynomials
- ne: returns NOT eq. This function is called when using the '~=' operator
- plus: Adds two polynomials
- subsasgn: Writes a polynomial to the (i,j) coordinate of a CoCoAPoly array
- subsref: Returns the (i,j) element of a CoCoAPoly array, {i,j} returns the element as a string
- times: Multiplies arrays of polynomials elementwise. If both arrays have the same dimension than each element of poly1 is multiplied with the corresponding element in poly2. If one of the poly's is a single value, this value is multiplied to each element in the other poly. If both poly's are single values they are simply multiplied.
- uminus: support for leading minus symbol
- uplus: support for leading plus symbol
Examples
A collection of examples is provided in the file TestCoCoAPoly.m. This file defines the function TestCoCoAPoly which will run and display many examples. A few common examples are presented below.
- Default polynomial: Constant 0 over Q[x[1]]
<matlab> pDefault = CoCoAPoly(); </matlab>
- Create two polynomials over same ring
<matlab> r1 = CoCoARing('Typ','Q','Indets',{'x','y'},'Ordering','DegRevLex'); p1 = CoCoAPoly('Ring', r1, 'Terms', [1 1 2 ; 1 2 1 ; 1 1 1]); p2 = CoCoAPoly('Ring', r1, 'Terms', [1 1 2 ; 1 0 0 ; 1 0 1]); </matlab>
- Add the two polynomials
<matlab> pAdded = p1+p2; </matlab>
- To read the attributes of a CoCoARing use the following command (this examples reads all attributes):
<matlab> [a1,a2] = get(p1,'Ring','Terms'); </matlab>
- Create an array of CoCoAPolys and access an element
<matlab> pArray = [p1,p2 ; p2,p1]; pElement = pArray(1,2); </matlab>