Message Boards Message Boards

0
|
1459 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

[?] Add a result of expression's differentiation result to string variable?

Posted 5 years ago

I need to create a list of expression differentials (1st, 2nd order and so on) and print results to the Grid. I'm trying to use next code (and a lot of other variants, but all were wrong). The problem is only in the line: ToString[D[z[x, y], {x, i - j}, {y, j}]].

MyFunction2[z_] := Block[ {x, y},
 arr = {{1, 1}, {1, 2, 1}, {1, 3, 3, 1}, {1, 4, 6, 4, 1}};
 result = {};
 For[i = 1, i <= 4, i++,
  res = "";
  For[j = 0, j <= i , j++,
   res = StringJoin[
    res,
    If[res == "", "", " + "], 
    If[arr[[i]][[j + 1]] > 1, 
    StringJoin[ToString[arr[[i]][[j + 1]]], "*"], ""],
    ToString[D[z[x, y], {x, i - j}, {y, j}]], 
    If[i - j > 0, "dx", ""],
    If[i - j > 1, StringJoin["^", ToString[ i - j]], ""], 
    If[j > 0, "dy", ""],
    If[j > 1, StringJoin["^", ToString[j]], ""]
   ];
  ];
  AppendTo[result, { StringJoin["d", If[i > 1, StringJoin["^", ToString[i]], ""], "z" ], res }];
   ];
  Grid[result, Frame -> All]
];
MyFunction2[Sin[x*y]]

I am expecting to have something like this as the result: | dz | yCos(xy)dx + xCos(xy)dy |

But result I have is (the first 2 rows of the Grid):enter image description here

Can you advise me please how can I convert the result of D[z[x, y], {x, i - j}, {y, j}] to the human-readable format? (I tried TraditionalForm[] but it is not what I exactly need)

POSTED BY: Dmitriy K
2 Replies
Posted 5 years ago
POSTED BY: Rohit Namjoshi
Posted 5 years ago

Thanks a lot! The great solution!

POSTED BY: Dmitriy K
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