CoCoA:HowTo:Plot polynomials

From ApCoCoAWiki
Revision as of 09:42, 29 October 2020 by AndraschkoBot (talk | contribs) (Bot: Replacing category HowTo with HowTo Old)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This article is a stub. You can make this wiki more useful by adding information.


Plotting multivariate polynomials may be quite complicated. Having a polynomial in more than two indeterminates, plotting its evaluation is tricky.

This How To covers how to plot an evaluation of a discrete set of points. There are two different approaches covered here. First we can evaluate the polynomial with CoCoA and then plot this evaluation with another tool, for example Matlab, gnuplot or another tool, or we can transfer the polynomial itself into another tool (we'll do it with Matlab) and then evaluate it over there.

Evaluate in CoCoA


Evaluate in Matlab

To evaluate a CoCoA polynomial in matlab we first have to translate / move it into matlab. I think, this is best done via a coefficient vector and a list of vectors, describing the logarithms of the supports elements.

to generate lists like this, you can use the following code:

P := ... --your polynomial

C := Coefficients(LC(M));
L := [ Log(M) |M In Support(P) ];

code by dheldt 09:03, 23 Sep 2005 (CEST)

Now C is the coefficient vector and L the list of logarithms. You can copy and paste them into matlab, but you have to make one change.

L := [[1,2],[0,1]]

has to be changed to

L = [[1,2];[0,1]]

because of some small differences between CoCoA's and Matlab's syntax.

To evaluate now the polynomials the following Matlab code can be used <matlab> function [p,m] = eval_cocoa_poly(C,L,R)

   s = size(R);
   m = zeros(s(1),length(C));
   p = zeros(s(1),1);
   for i=1:1:length(C)
       h = ones(s(1),1);
       for j =1:1:s(2)
           h = h.*(R(:,j)).^(L(i,j));
       m(:,i) = C(i)*h;
       p    = p + C(i)*h;


code by dheldt 09:03, 23 Sep 2005 (CEST)

C and L are described above. It's the coefficient vector and a matric, which rows are the support's elements logarithms. R is a matrix. Its columns represent the indetermintates and each row is one point, where the polynomial should be evaluated. The function returns p and m, where p is the polynomial evaluation at all the points and m is the evaluation of all the monomials at all the points.