Message Boards Message Boards

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

Evaluate a function when a button is clicked in Manipulate?

I am using Mathematica 11.3. I have been wrestling with the following issue for a while and suspect I have a conceptual difficulty as I can find nothing relevant on web searches so would appreciate any assistance appreciated.

In this example with the function test defined. I am trying to get the sum of n1 and n2 when the button is pressed. I have tried multiple manipulates, dynamic,evaluate, @, @@ but at best all that prints is

test[2,3]

where 2 and 3 would be the current slider values

What follows is sample code

test[a, b] := a + b;

Manipulate[
 myPlot = Plot[Sin[n1 x] + Sin[n2 x], {x, 0, 2 Pi}, PlotRange -> 2],
 {n1, 1, 20}, {n2, 1, 20},

 Row[{Spacer[100], Button["Add n1 and n2",
    Print[Evaluate[test[n1, n2]]],  Method -> "Queued", 
    ImageSize -> 100]}]
 ]
POSTED BY: William Taylor
2 Replies
POSTED BY: William Taylor

Sorry to bother I see the error here (forgot the underscores in the function definition) I will have to reformulate my request as this does not work for more complex functions in the context I am using them

Still any suggestions on evaluating two functions using current parameter values in a manipulate would be helpful

test[a_, b_] := a + b;

Manipulate[ myPlot = Plot[Sin[n1 x] + Sin[n2 x], {x, 0, 2 Pi}, PlotRange -> 2], {n1, 1, 20}, {n2, 1, 20},

Row[{Spacer[100], Button["Add n1 and n2", Print[Evaluate[test[n1, n2]]], Method -> "Queued", ImageSize -> 100]}] ]
POSTED BY: William Taylor
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