Message Boards Message Boards

0
|
4026 Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How may we write Nth polynomials and perform their derivatives?

Posted 2 years ago

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,

  1. Is there another way to express the general form of $P(x,y)$ as presented above using Mathematica
  2. How may I express the $P(x,y)$ derivatives?

Thanks in advance

Attachments:
5 Replies
Posted 2 years ago

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?

POSTED BY: Rohit Namjoshi

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

POSTED BY: Henrik Schachner

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]

POSTED BY: Gianluca Gorni

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.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract