在 Maple 中以编程方式使用泰勒多项式

发布于 2024-08-13 16:51:47 字数 532 浏览 6 评论 0原文

我试图在 Maple 中以编程方式使用泰勒多项式,但以下内容似乎不起作用...

T[6]:=taylor(sin(x),x=Pi/4,6);convert(T[6], polynom, x);
f:=proc(x)
  convert(T[6], polynom, x);
end proc;
f(1);

以下所有内容也不起作用:

  • f:=convert(T[6], polynom);f:=convert(T[6], polynom);
  • f:=convert(T[6], 多项式, x);
  • f:=x->convert(T[6], 多项式);
  • >f:=x->convert(T[6], 多项式, x);.

有没有一种方法可以做到这一点,而无需将 Convert 的输出复制并粘贴到 f 的定义中?

I am trying to use a Taylor polynomial programmatically in Maple, but the following does not seem to work...

T[6]:=taylor(sin(x),x=Pi/4,6);convert(T[6], polynom, x);
f:=proc(x)
  convert(T[6], polynom, x);
end proc;
f(1);

All of the following also do not work:

  • f:=convert(T[6], polynom);
  • f:=convert(T[6], polynom, x);
  • f:=x->convert(T[6], polynom);
  • f:=x->convert(T[6], polynom, x);.

Is there a way of doing this without copying and pasting the output of convert into the definition of f?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

简单爱 2024-08-20 16:51:47

如果我理解正确的话,这可以实现你想要的:

f := proc(z)
    local p :: polynom;
    p := convert(T[6], polynom); 
    return subs(x = z, p)
end proc

If I understood you correctly, this accomplishes what you want:

f := proc(z)
    local p :: polynom;
    p := convert(T[6], polynom); 
    return subs(x = z, p)
end proc
爱情眠于流年 2024-08-20 16:51:47

涉及过程和子程序的几个早期答案将为每个输入进行整个泰勒级数推导,以及转换为多项式。这是非常低效的。

您只需要生成泰勒结果并转换为多项式一次。有了这个结果,您就可以创建一个运算符(用它可以对任意数量的输入进行操作,只需评估该点的多项式,但无需重新计算整个泰勒答案)。

下面是创建过程 f 的方法,用它在任何给定点对参数 x 进行计算。它计算(截断的)泰勒级数并仅一次转换为多项式。

> f:=unapply(convert(taylor(sin(x),x=Pi/4,6),polynom),x):

Several earlier answers involving procedures and subs will do the entire taylor series derivation, as well as the conversion to polynom, for each and every input. That is highly inefficient.

You only need to produce the taylor result, and convert to polynom, once. With that result in hand you can then create an operator (with which to act on as many inputs as you wish, merely by evaluating the polynomial at the point but without having to recompute the whole taylor answer).

Below is a way to create a procedure f with which to evaluate at any given point for the argument x. It computes the (truncated) taylor series and converts to polynom just once.

> f:=unapply(convert(taylor(sin(x),x=Pi/4,6),polynom),x):
花桑 2024-08-20 16:51:47

将 T 定义为函数也可能是很自然的。

T:=y->subs(x=y,convert(taylor(sin(x),x=Pi/4,6),polynom));

T(1);

It might also be natural to define T as a function.

T:=y->subs(x=y,convert(taylor(sin(x),x=Pi/4,6),polynom));

T(1);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文