viniciusx10
(VinĂcius Hopkins)
May 17, 2022, 10:42pm
1
Suppose a multivariable polynomial of Nth degree is given by
P(x,y)=\displaystyle\sum_{j=0}^{N}\sum_{i=0}^{j} a_{i,\,j-i}x^{i}y^{j-i} .
I want to express this polynomial using Mathematica. In addition, It is of my interest compute its first and second derivatives.
My attempts:
Previously, I tried to study the derivatives of the P(x,y) through a generator of polynomial using the following code:
poly[vars_List, a_, order_] := Module[{n = Length@vars, idx, z},
idx = Cases[Tuples[Range[0, order], n], x_ /; Plus @@ x <= order]; z = Times @@@ (vars^# & /@ idx); z.((Subscript[a, Row[#]]) & /@ idx)]
poly[{x, y}, a, n]
However, it looks like that this code only works when n is equal to some integer number, for example, n =2. Otherwise, I receive an error message.
Attached below, you may find my notebook with my attempts.
Based on the above,
Is there another way to express the general form of P(x,y) as presented above using Mathematica
How may I express the P(x,y) derivatives?
Thanks in advance
Mydoubts.nb (6.2 KB)
Hi VinĂcius
One issue is that N is a built-in symbol. Try
ClearAll@n
poly[{x, y}, a, n]
Range[0, n] is unbounded. Is there a reason why you cannot use Sum to generate the polynomial?
VinĂcius,
as Rohit proposed those polynomials and their derivatives can be formulated in a very general way, e.g.:
p = Sum[a[i, j - i] x^i y^(j - i), {j, 0, n}, {i, 0, j}]
(* simple check: *)
p /. n -> 4
(* e.g.: first derivative in x, second in y: *)
dp = D[p, {x, 1}, {y, 2}]
dp /. n -> 4
Does that help? Regards – Henrik
You mean you want an expression that is human-readable even when the order is a symbol? Here is an attempt:
poly[vars_List, a_, order_Integer /; order >= 0] :=
Module[{n = Length@vars, idx, z},
idx = Select[Tuples[Range[0, order], n], Total[#] <= order &];
Plus @@
Table[Subscript[a, Sequence @@ r] Times @@ (vars^r), {r, idx}]];
poly[vars_List /; Length[vars] > 2, a_, order_] :=
Inactive[Sum][
Inactive[Times][
Subscript[a, Subscript["i", 1], \[Ellipsis],
Subscript["i", Length[vars]]], vars[[1]]^
Subscript["i", 1], \[Ellipsis], vars[[-1]]^
Subscript["i", Length[vars]]],
0 <= Inactive[Plus][Subscript["i", 1], \[Ellipsis],
Subscript["i", Length[vars]]] <= order]
Try poly[{x, y, z, t}, a, n]
Hi Mr. Schachner, I hope you are doing well.
Thank you for your insightful comment. Indeed, I have also tried to compute P(x,y) using Sum. However, it did not work nicely in the general case. Nevertheless, your code has clarified all of my doubts.
Thanks once more, and God bless you.
Thanks for your comments. Your code is quite interesting.