1
$\begingroup$

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.

$\endgroup$
5
  • 2
    $\begingroup$ Caution: xy is not the same as x*y $\endgroup$
    – Mr.Wizard
    Commented Jul 1, 2015 at 22:23
  • $\begingroup$ Did you want something like SetterBar[Dynamic[variable], {x, y}]? Then D[func, variable], wherever you need it, would give the partial derivative. $\endgroup$
    – Michael E2
    Commented Jul 1, 2015 at 22:41
  • 1
    $\begingroup$ 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. $\endgroup$
    – Michael E2
    Commented Jul 2, 2015 at 14:15
  • $\begingroup$ @Michael E2: I apologize for my mistake. I will heed your comment next time. I am truly sorry. $\endgroup$
    – Shellp
    Commented Jul 2, 2015 at 15:07
  • 1
    $\begingroup$ @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. $\endgroup$
    – Michael E2
    Commented Jul 2, 2015 at 15:12

2 Answers 2

1
$\begingroup$

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]

enter image description here

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

$\endgroup$
0
3
$\begingroup$

My comment in Manipulate form:

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

Mathematica graphics

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

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.