Question: Explore. Using function inside Explore problems

To help debug things, and to make it easier to add more logic such as if then else and so on, I moved the main body of Explor to a separate proc where the plot is made after doing some checking.

So instead of writing

Explore(plot(.....), 
 parameters=[  
   [c=0..10,....],
   [k=0..10,...]]
)

It now became

foo:=proc(c,k}
.....#some debug print messages added here, and some checking...
   plot(....)
end proc;

Explor( foo(c,k), 
  parameters=[  
    [c=0..10,....],
    [k=0..10,...]]
)

Two problems. 

1) My print lines inside foo() do not print to worksheet. Only the initial time they do. When I mean initial time, it is when Explore starts and does initalization. I see the print lines only then.

But after that, as I change the slider, which should make a call to foo(), I see nothing printed on the screen in my worksheet any more.

It is as if Explor stopped calling my foo().  But at same time, I see do see in the the display of Explore itself that it is calling foo as expected, since the call it display is changes and the result of the call changes as slider is changed. So call is being made. 

This is what shows inside Explore...

foo(5,2)=10
foo(3,2)=6
and so on

Why then the print messages from foo() are not printed in the worksheet any more? Where are the print message going to then?

2) How to make Explor only show the _result_ of calling foo() and not show the call itself as it does now? 

ie. instead of showing foo(5,2)=10  I just wanted to see the result of foo, which is 10 in this example.

Doing rhs(foo(c,k)) did not work

Here is worksheet to see yourself.

restart;

foo:=proc(c,k)
   print("c=",c," k=",k);
   c*k;
end proc:

Explore(foo(c,k),
   initialvalues=[c=1,k=.1],
   parameters=[
     [c=0..10,'controller' = 'slider','minorticks'=1,
      'snaptoticks'=true, 'label' = "Damping c",'showlabels'=false],
     [k=0..10,'controller' = 'slider','minorticks'=1,
      'snaptoticks'=true, 'label' = "Stiffness k",'showlabels'=false]]
   );

"c=", 10, " k=", 10

"c=", 0, " k=", 0

"c=", 1, " k=", .1

 


 

Download explore_feb_28_2026.mw

Here is small movie

ps. I am thinking now Explore only works with "plot" as its first argument. But help says expr can be anything.

Please Wait...