I have a function like fun[a_, k_] := Exp[a x] + Cos[k t] I want to see how the function behaves when the parameters a and k change. So, I wrote a code as follows:

 Plot3D[fun[a, k], {x, -5, 5}, {t, 0, 8}], {a, -2, 2, 0.5}, {k, -1, 3,
   0.5}, Initialization :> {fun[a_, k_] := Exp[a x] + Cos[k t]}]

I want to see the value of the function (fun[a, k]) dynamically on the panel or on the graph when I move the a and k values.

Besides, suppose that I derive the plot which I want for a=1, k=0, I want to copy the value (Exp[ x] + 1) of the function from the panel in order to use in the next steps. (Second option; we can assign the values of the function to a new parameter. So, we can use this parameter in the next steps.)

(P.S. This is a simple example. In fact, I have more difficult functions including more parameters.)

enter image description here


1 Answer 1


I hope I understand correctly what you are looking for. To show the current parameter values in the graphics, you may use "PlotLabel". And to store the current parameters to make them accessible outside the manipulate, you can store the parameters in a global variable.

Here is your example:

Manipulate[(param = {a, k}; 
  Plot3D[fun[a, k], {x, -5, 5}, {t, 0, 8}, 
   PlotLabel -> StringForm["a=``, k=``", a, k]]), {a, -2, 2, 
  0.5}, {k, -1, 3, 0.5}, 
 Initialization :> {fun[a_, k_] := Exp[a x] + Cos[k t]}]

enter image description here

The parameters are available in the variable param:

(* {-2, -1} *)
  • $\begingroup$ Thank you. It's almost what I want. Now, I can achieve the rest. $\endgroup$ Jan 4, 2022 at 21:09

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.