# Ask about the variable and constants in partial derivative in a loop

EDITED

I have a function in a list like :

func={2(x^2)+x*y+3(y^2)};


I want to have a UI that ask me which parameter (x or y) is a variable in a Do[] loop, then calculate the partial derivatives of func with respect to that variable and in each iteration ask again; then use the output in another equation.For example :

*1st. iteration
-variable is y
-calculate the partial derivative func with respect to y
-output is x+6y
-save the output in a list {{x+6y}}

*2nd. iteration
-variable is x
-calculate the partial derivative func with respect to x
-output is 4x+y
-save the output in a list {{4x+y}}

Finallist={{x+6y},{4x+y}}


I would be appreciated if you could help me. Thank you in advance.

• Caution: xy is not the same as x*y Jul 1, 2015 at 22:23
• Did you want something like SetterBar[Dynamic[variable], {x, y}]? Then D[func, variable], wherever you need it, would give the partial derivative. Jul 1, 2015 at 22:41
• It's bad form to alter a question so much, esp. to add a requirement of a loop where there was none originally. You make the answers and work others have done on your behalf seem irrelevant. SE is not a private consulting service but a public Q&A forum. Please, either ask the question you need to ask the first time, or ask a new question. Jul 2, 2015 at 14:15
• @Michael E2: I apologize for my mistake. I will heed your comment next time. I am truly sorry. Jul 2, 2015 at 15:07
• @Shellp Don't worry about it too much. It's not the first time it's happened. But it helps to keep the site coherent for future visitors with the same or similar problems, if the answers and questions go together. (It also keeps the orphaned answers from looking like the poster couldn't even read the question.) Thanks for the response, and cheers. Jul 2, 2015 at 15:12

This should produce the desired dialog loop

pdGUIstyled[func_, outputList_: {}] := Setting@DynamicModule[{variable},
Module[{symboles = Cases[func, _Symbol, Infinity] // DeleteDuplicates, lastRes},
Column[{
Row[{"the function is: ", Panel[func, Background -> White]}],
"",
Row[{"the current list of derivatives: ",
Panel[outputList, Background -> LightBlue]}],
Row[{"Select next variable: ",
SetterBar[Dynamic@variable, symboles, BaseStyle -> {Large}]}],
Row[{DefaultButton["Next Variable",
DialogReturn[Append[outputList, D[func, variable]]]],
CancelButton[]}]
}], Modal -> True
];
If[ListQ@lastRes, pdGUIstyled[func, lastRes], outputList]
]]


Usage

func = {2 (x^2) + x*y + 3 (y^2)};
finalList = pdGUIstyled[func]


{{4 x + y}, {x + 6 y}}

My comment in Manipulate form:

func = {x^2 + x y + y^2};
Manipulate[
D[func, variable],
{variable, {x, y}}
]


The control that Manipulate uses is the SetterBar[Dynamic[variable], {x, y}] of my comment.