CoCoA:HowTo:Plot polynomials

From ApCoCoAWiki
Revision as of 14:53, 15 October 2007 by Dheldt (talk | contribs) (Plotting polynomials moved to HowTo:Plot polynomials: tidying up the wiki...)

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

About

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

[ToDo]

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));
C;
L := [ Log(M) |M In Support(P) ];
L;

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));
       end;    
       m(:,i) = C(i)*h;
       p    = p + C(i)*h;
   end;

return;</matlab>

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.

Examples

[ToDo]