Maxima 中函数的多元多项式逼近

Multivariate polynomial approximation of a function in Maxima

我在Maxima中有很长的符号函数,比方说

fn(x,y):=<<some long equation using x and y>>

我想计算这个函数的多项式逼近,比方说

fn_poly(x,y)

xy 的已知范围内,最大误差 e

我知道,Maxima 中有一个功能,例如plsquares,但它需要一个输入矩阵,而我只有函数 fn(x,y)。我不知道如何从我的函数生成这个矩阵。 genmatrix 创建了 plsquares 无法使用的矩阵。

这在 Maxima 中可行吗?

创建列表列表并将其转换为矩阵。

load(plsquares);
f(x,y):=x^2+y^3;
mat:makelist(makelist([X,Y,f(X,Y)],X,1,10,2),Y,1,10,2);

-> [[[1,1,2],[3,1,10],[5,1,26],[7,1,50],[9,1,82]],[[1,3,28],[3,3,36],[5,3,52],[7,3,76],[9,3,108]],[[1,5,126],[3,5,134],[5,5,150],[7,5,174],[9,5,206]],[[1,7,344],[3,7,352],[5,7,368],[7,7,392],[9,7,424]],[[1,9,730],[3,9,738],[5,9,754],[7,9,778],[9,9,810]]]

mat2:[];
for i:1 thru length(mat) do mat2:append(mat2,mat[i]);
mat3:funmake('matrix,mat2);

-> matrix([1,1,2],[3,1,10],[5,1,26],[7,1,50],[9,1,82],[1,3,28],[3,3,36],[5,3,52],[7,3,76],[9,3,108],[1,5,126],[3,5,134],[5,5,150],[7,5,174],[9,5,206],[1,7,344],[3,7,352],[5,7,368],[7,7,392],[9,7,424],[1,9,730],[3,9,738],[5,9,754],[7,9,778],[9,9,810])

ZZ:rhs(plsquares(mat3,[X,Y,Z],Z,3,3));

-> Determination Coefficient for Z = 1.0
-> Y^3+X^2