1

Could someone help me understand why this code does not work?

enter image description here

I paste the code here but I am unable to format it:

PacletInstall["https://github.com/carlwoll/DifferentialOperator/releases/download/0.1/DifferentialOperator-0.0.1.paclet"]

($Failed)

PacletUninstall

(PacletUninstall)

PacletInstall[ForceVersionInstall -> True]

(PacletInstall[ForceVersionInstall -> True])

    ( {
   {Subscript[\[PartialD], x], 0},
   {0, Subscript[\[PartialD], x]}
  } ) . ( {
   {x^2},
   {E^ax}
  } )

I have tried the following:

enter image description here

But this does not apply the operators to the right hand side matrix

NC520
  • 479
  • 1
  • 7
  • Have you tried to follow the first warning and re-install the package, and then Get that package? – Lacia Dec 01 '22 at 00:45
  • Yes, I have run PacletUninstall as well as PacletInstall[ForceVersionInstall -> True] and still doesn't work – NC520 Dec 01 '22 at 00:50
  • 1
    I'm not familiar with his package, but with Subscript[\[PartialD], x] replaced by DifferentialOperator[x], I get {{x^2 Subscript[\[PartialD], x]},{E^ax Subscript[\[PartialD], x]}}. Is this what you expect? – Lacia Dec 01 '22 at 01:13
  • Helpful, but not quite what I need. I would need the operator to be applied to the elements of the second matrix. I will update the question accordingly – NC520 Dec 01 '22 at 01:20

1 Answers1

1

If you read the corresponding examples for the package shown in this post carefully, you'll notice the operator created by the package and the expression to be differentiated isn't linked by Times, but Construct i.e. code like

L = DifferentialOperator[x];
L@Exp[a x]

will work, but

L = DifferentialOperator[x];
L Exp[a x]

won't. This design is reasonable, because Times is commutative, but differential operator is not. Dot (.) evaluates to combination of Times and Plus so DifferentialOperator won't work in it, either.

To fix the code, we can use Inner as shown in this and this post:

Inner[If[FreeQ[#1, DifferentialOperator], Times[##], Construct[##]] &,
      {{DifferentialOperator[x], 0}, 
       {0, DifferentialOperator[x]}}, 
      {x^2, Exp[a x]}]

(* {2 x, a E^(a x)} *)

xzczd
  • 65,995
  • 9
  • 163
  • 468
  • Thank you. I think I am totally confused though. I still don't obtain your result. My output is {DifferentialOperator[x][x^2], DifferentialOperator[x][E^(a x)]} – NC520 Dec 01 '22 at 09:46
  • 1
    @nc520 Sounds like you haven't loaded the package. Have you executed `<<DifferentialOperator``? – xzczd Dec 01 '22 at 10:07
  • Thanks it worked. Excellent answer – NC520 Dec 01 '22 at 11:31