Adding a result of expression differentiation to the string variable












0















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). I think 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 the result I have is:
image with grid



Can you advise me please how to print results in a human-readable format?










share|improve this question

























  • No, the "result" list is populated by 4 pairs of values correctly. My question is: How can I convert the result of D[z[x, y], {x, i - j}, {y, j}] to the human-readable format? (other parts of code are here for the ability to copy-paste and run)

    – Dmitriy
    Nov 20 '18 at 19:16













  • Does putting TraditionalForm around your expressions at exactly the right places get you closer to what you want? That is supposed to translate Mathematica form to human-readable form. If that isn't enough then you may have to write your own version of TraditionalForm

    – Bill
    Nov 20 '18 at 20:03













  • I tried to use TraditionalForm, but the result wasn't exactly what I need. It seems that you are right, I need my own function. Thank you, Bill!

    – Dmitriy
    Nov 20 '18 at 21:01
















0















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). I think 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 the result I have is:
image with grid



Can you advise me please how to print results in a human-readable format?










share|improve this question

























  • No, the "result" list is populated by 4 pairs of values correctly. My question is: How can I convert the result of D[z[x, y], {x, i - j}, {y, j}] to the human-readable format? (other parts of code are here for the ability to copy-paste and run)

    – Dmitriy
    Nov 20 '18 at 19:16













  • Does putting TraditionalForm around your expressions at exactly the right places get you closer to what you want? That is supposed to translate Mathematica form to human-readable form. If that isn't enough then you may have to write your own version of TraditionalForm

    – Bill
    Nov 20 '18 at 20:03













  • I tried to use TraditionalForm, but the result wasn't exactly what I need. It seems that you are right, I need my own function. Thank you, Bill!

    – Dmitriy
    Nov 20 '18 at 21:01














0












0








0








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). I think 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 the result I have is:
image with grid



Can you advise me please how to print results in a human-readable format?










share|improve this question
















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). I think 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 the result I have is:
image with grid



Can you advise me please how to print results in a human-readable format?







wolfram-mathematica






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 4 '18 at 15:46









kvantour

8,92331330




8,92331330










asked Nov 20 '18 at 17:24









DmitriyDmitriy

32




32













  • No, the "result" list is populated by 4 pairs of values correctly. My question is: How can I convert the result of D[z[x, y], {x, i - j}, {y, j}] to the human-readable format? (other parts of code are here for the ability to copy-paste and run)

    – Dmitriy
    Nov 20 '18 at 19:16













  • Does putting TraditionalForm around your expressions at exactly the right places get you closer to what you want? That is supposed to translate Mathematica form to human-readable form. If that isn't enough then you may have to write your own version of TraditionalForm

    – Bill
    Nov 20 '18 at 20:03













  • I tried to use TraditionalForm, but the result wasn't exactly what I need. It seems that you are right, I need my own function. Thank you, Bill!

    – Dmitriy
    Nov 20 '18 at 21:01



















  • No, the "result" list is populated by 4 pairs of values correctly. My question is: How can I convert the result of D[z[x, y], {x, i - j}, {y, j}] to the human-readable format? (other parts of code are here for the ability to copy-paste and run)

    – Dmitriy
    Nov 20 '18 at 19:16













  • Does putting TraditionalForm around your expressions at exactly the right places get you closer to what you want? That is supposed to translate Mathematica form to human-readable form. If that isn't enough then you may have to write your own version of TraditionalForm

    – Bill
    Nov 20 '18 at 20:03













  • I tried to use TraditionalForm, but the result wasn't exactly what I need. It seems that you are right, I need my own function. Thank you, Bill!

    – Dmitriy
    Nov 20 '18 at 21:01

















No, the "result" list is populated by 4 pairs of values correctly. My question is: How can I convert the result of D[z[x, y], {x, i - j}, {y, j}] to the human-readable format? (other parts of code are here for the ability to copy-paste and run)

– Dmitriy
Nov 20 '18 at 19:16







No, the "result" list is populated by 4 pairs of values correctly. My question is: How can I convert the result of D[z[x, y], {x, i - j}, {y, j}] to the human-readable format? (other parts of code are here for the ability to copy-paste and run)

– Dmitriy
Nov 20 '18 at 19:16















Does putting TraditionalForm around your expressions at exactly the right places get you closer to what you want? That is supposed to translate Mathematica form to human-readable form. If that isn't enough then you may have to write your own version of TraditionalForm

– Bill
Nov 20 '18 at 20:03







Does putting TraditionalForm around your expressions at exactly the right places get you closer to what you want? That is supposed to translate Mathematica form to human-readable form. If that isn't enough then you may have to write your own version of TraditionalForm

– Bill
Nov 20 '18 at 20:03















I tried to use TraditionalForm, but the result wasn't exactly what I need. It seems that you are right, I need my own function. Thank you, Bill!

– Dmitriy
Nov 20 '18 at 21:01





I tried to use TraditionalForm, but the result wasn't exactly what I need. It seems that you are right, I need my own function. Thank you, Bill!

– Dmitriy
Nov 20 '18 at 21:01












1 Answer
1






active

oldest

votes


















0














May not be exactly what you are looking for, but should be easy to modify.



derivativeGrid[f_Function, xmax_Integer, ymax_Integer] := 
Module[{derivatives, rowHeader, columnHeader, grid},
derivatives =
Table[D[f[x, y], {x, i}, {y, j}], {i, 0, xmax}, {j, 0, ymax}];
columnHeader = Table["dx"^x, {x, 0, xmax}];
rowHeader = Join[{""}, Table["dy"^y, {y, 0, ymax}]];
grid = MapThread[Prepend, {Prepend[derivatives, columnHeader], rowHeader}];
Grid[grid, ItemStyle -> {{1 -> Bold}, {1 -> Bold}},
Background -> {{LightYellow, None}, {LightYellow, None}},
Frame -> All]]


Since it computes derivatives of a function of two arguments f[x, y], it needs to be passed a function of two arguments.



derivativeGrid[Sin[#1*#2] &, 3, 3]


enter image description here






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398334%2fadding-a-result-of-expression-differentiation-to-the-string-variable%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    May not be exactly what you are looking for, but should be easy to modify.



    derivativeGrid[f_Function, xmax_Integer, ymax_Integer] := 
    Module[{derivatives, rowHeader, columnHeader, grid},
    derivatives =
    Table[D[f[x, y], {x, i}, {y, j}], {i, 0, xmax}, {j, 0, ymax}];
    columnHeader = Table["dx"^x, {x, 0, xmax}];
    rowHeader = Join[{""}, Table["dy"^y, {y, 0, ymax}]];
    grid = MapThread[Prepend, {Prepend[derivatives, columnHeader], rowHeader}];
    Grid[grid, ItemStyle -> {{1 -> Bold}, {1 -> Bold}},
    Background -> {{LightYellow, None}, {LightYellow, None}},
    Frame -> All]]


    Since it computes derivatives of a function of two arguments f[x, y], it needs to be passed a function of two arguments.



    derivativeGrid[Sin[#1*#2] &, 3, 3]


    enter image description here






    share|improve this answer






























      0














      May not be exactly what you are looking for, but should be easy to modify.



      derivativeGrid[f_Function, xmax_Integer, ymax_Integer] := 
      Module[{derivatives, rowHeader, columnHeader, grid},
      derivatives =
      Table[D[f[x, y], {x, i}, {y, j}], {i, 0, xmax}, {j, 0, ymax}];
      columnHeader = Table["dx"^x, {x, 0, xmax}];
      rowHeader = Join[{""}, Table["dy"^y, {y, 0, ymax}]];
      grid = MapThread[Prepend, {Prepend[derivatives, columnHeader], rowHeader}];
      Grid[grid, ItemStyle -> {{1 -> Bold}, {1 -> Bold}},
      Background -> {{LightYellow, None}, {LightYellow, None}},
      Frame -> All]]


      Since it computes derivatives of a function of two arguments f[x, y], it needs to be passed a function of two arguments.



      derivativeGrid[Sin[#1*#2] &, 3, 3]


      enter image description here






      share|improve this answer




























        0












        0








        0







        May not be exactly what you are looking for, but should be easy to modify.



        derivativeGrid[f_Function, xmax_Integer, ymax_Integer] := 
        Module[{derivatives, rowHeader, columnHeader, grid},
        derivatives =
        Table[D[f[x, y], {x, i}, {y, j}], {i, 0, xmax}, {j, 0, ymax}];
        columnHeader = Table["dx"^x, {x, 0, xmax}];
        rowHeader = Join[{""}, Table["dy"^y, {y, 0, ymax}]];
        grid = MapThread[Prepend, {Prepend[derivatives, columnHeader], rowHeader}];
        Grid[grid, ItemStyle -> {{1 -> Bold}, {1 -> Bold}},
        Background -> {{LightYellow, None}, {LightYellow, None}},
        Frame -> All]]


        Since it computes derivatives of a function of two arguments f[x, y], it needs to be passed a function of two arguments.



        derivativeGrid[Sin[#1*#2] &, 3, 3]


        enter image description here






        share|improve this answer















        May not be exactly what you are looking for, but should be easy to modify.



        derivativeGrid[f_Function, xmax_Integer, ymax_Integer] := 
        Module[{derivatives, rowHeader, columnHeader, grid},
        derivatives =
        Table[D[f[x, y], {x, i}, {y, j}], {i, 0, xmax}, {j, 0, ymax}];
        columnHeader = Table["dx"^x, {x, 0, xmax}];
        rowHeader = Join[{""}, Table["dy"^y, {y, 0, ymax}]];
        grid = MapThread[Prepend, {Prepend[derivatives, columnHeader], rowHeader}];
        Grid[grid, ItemStyle -> {{1 -> Bold}, {1 -> Bold}},
        Background -> {{LightYellow, None}, {LightYellow, None}},
        Frame -> All]]


        Since it computes derivatives of a function of two arguments f[x, y], it needs to be passed a function of two arguments.



        derivativeGrid[Sin[#1*#2] &, 3, 3]


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 22:14

























        answered Nov 20 '18 at 21:51









        Rohit NamjoshiRohit Namjoshi

        31718




        31718
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398334%2fadding-a-result-of-expression-differentiation-to-the-string-variable%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?