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
-ask about the variable
-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
-ask about the variable
-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.

=================

2

 

Caution: xy is not the same as x*y
– Mr.Wizard♦
Jul 1 ’15 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.
– Michael E2
Jul 1 ’15 at 22:41

1

 

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.
– Michael E2
Jul 2 ’15 at 14:15

  

 

@Michael E2: I apologize for my mistake. I will heed your comment next time. I am truly sorry.
– Shellp
Jul 2 ’15 at 15:07

1

 

@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.
– Michael E2
Jul 2 ’15 at 15:12

=================

2 Answers
2

=================

This should produce the desired dialog loop

pdGUIstyled[func_, outputList_: {}] := Setting@DynamicModule[{variable},
Module[{symboles = Cases[func, _Symbol, Infinity] // DeleteDuplicates, lastRes},
lastRes = DialogInput[
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.