-2

我想计算数学中的系数。例如,我编写了这段代码来查找 (a+b*cos(x))^4 中 cos(kx) 的系数,其中“a”和“b”是参数。

f[x_] := (a + b Cos[x])^4

f1[x_] := TrigReduce[f[x]]

g[x_, k_] := Coefficient[f1[x], Cos[k x]]

它适用于 cos(k*x) 的系数,

例如 cos(2x) 的系数是

g[x,2]= 1/8 (24 a^2 b^2 + 4 b^4)

但它不适用于常数(这里常数意味着独立于 cos(kx)。换句话说,只是带有数字和参数“a”和“b”的术语)。

我想编写代码来查找上述含义中的常量。

谢谢。

4

1 回答 1

1

Plugging Coefficient[TrigReduce[(a + b*Cos[x])^4],Cos[2*x]] into Wolfram|Alpha produced the output you wanted it to. This leads me to suggest that your problem might have to do with how the expression is being evaluated as opposed to a problem with how you are mathematically thinking about it.

I do not have access to a copy of Mathematica so can not test this, but I would try changing := to = in the second line of code.

I would also try putting it all in one line as

g[x_, k_] := Coefficient[TrigReduce[(a + b Cos[x])^4], Cos[k x]]

If that works, it is definitely something wrong with how/when Mathematica is assigning stuff.

See this link for more information.

于 2012-06-08T02:08:41.520 回答