Group Abstract Group Abstract

Message Boards Message Boards

[?] Manipulate a dynamicly generated expression?

Posted 8 years ago
POSTED BY: zare bozas
5 Replies
POSTED BY: Neil Singer

Zare,

  1. Either are ok in this case, however, Sometimes you evaluate an expression that contains a variable, ie "x". and then want to create a function of x from the evaluated expression, you would use = if you want to evaluate the expression immediately.

  2. You need to be a bit clever to do the dynamic number of parameters to Manipulate. Here is an example that creates at list of the variables in an expression (data) and then constructs the Manipulate that you want.

Lets create a function to get all the variables in an expression:

findAllVars[eqns_] := 
 DeleteCases[
  Union[Flatten[
    Replace[eqns , head_[args___] -> List[args], {0, Infinity}]]], 
  x_ /; NumericQ[x]]

Now we can use it in your example. I assume that "data" contains your expression -- you can also make this a function of data instead of having data being global.

With[{arr = Arrow[data], 
  varSliders = Sequence @@ Map[{#, 0, 100} &, findAllVars[data]]}, 
 Manipulate[
  Graphics3D[{arr, region}, Axes -> True, ViewPoint -> Front], 
  varSliders]]

You need a "With" to place the arrow expression into the Manipulate because Manipulate has attribute HoldAll. You need to construct a sequence to specify the slider variables to the Manipulate. Again, you need to insert the sequence using With. The Map constructs the arguments in the proper format for Manipulate.

I hope this helps.

Regards,

Neil

POSTED BY: Neil Singer
Posted 8 years ago

Thanks,

Yes, it works for me too now. I have 2 questions more:

  1. Why dont you use := for the assignment of the variable "arrow" with parameter?
  2. Like already asked in the first post: Is there a posibility to pass an dynamic count of parameters to the Manipulate function based at the "angles" variable?

Regards

POSTED BY: zare bozas

Zare,

Your error is because you need to quit the kernel. You defined arrows one way and I changed the way it is used in the posted code. The code I posted works with your example if you delete ShowAll code and use what I posted instead.

Regards

POSTED BY: Neil Singer
Posted 8 years ago

Yes, I know that the arrow is a function of x, but only in this example. I d like to write a universal function, which also allows 2, 3 or more Links. In that cases they would be 2 or 3 parameters. Also i will have the same error which I had already before:

"Tag Arrow in Arrow[{{{1,1,............ ........}}}][x_] is Protected"

POSTED BY: zare bozas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard