Difference between revisions of "CoCoA:HowTo:Plot polynomials"
(→Evaluate in Matlab: adding some content) |
m (Bot: Replacing category HowTo with HowTo Old) |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 21: | Line 21: | ||
P := ... --your polynomial | P := ... --your polynomial | ||
− | C := | + | C := Coefficients(LC(M)); |
C; | C; | ||
− | L := [ Log | + | L := [ Log(M) |M In Support(P) ]; |
L; | L; | ||
code by [[User:Dheldt|dheldt]] 09:03, 23 Sep 2005 (CEST) | code by [[User:Dheldt|dheldt]] 09:03, 23 Sep 2005 (CEST) | ||
Line 36: | Line 36: | ||
To evaluate now the polynomials the following Matlab code can be used | 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); | s = size(R); | ||
m = zeros(s(1),length(C)); | m = zeros(s(1),length(C)); | ||
Line 50: | Line 50: | ||
end; | end; | ||
− | return; | + | return;</matlab> |
code by [[User:Dheldt|dheldt]] 09:03, 23 Sep 2005 (CEST) | code by [[User:Dheldt|dheldt]] 09:03, 23 Sep 2005 (CEST) | ||
Line 61: | Line 61: | ||
[ToDo] | [ToDo] | ||
− | [[ | + | [[Category:HowTo Old]] |
+ | [[Category:CoCoA4]] |
Latest revision as of 09:42, 29 October 2020
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]