Message Boards Message Boards

2
|
7047 Views
|
9 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Updating dependant input fields?

Posted 8 years ago

Hi, first time posting

Let's say I want to have 3 input fields,

[field one]
[field two]
[field three]

I want to describe a relationship between these three boxes. Let's just say

F1 = 2(F2) = 3(F3)

The key functionality that I'm looking for is to be able to update any of the field input boxes and have all the other ones self update with respect to the relationship described above. Obviously the end application is going to be more complex than this, but this should give me a good idea on how I can set it up. This is my code so far, needless to say it's not working.

Manipulate[F1 = 2*F2 = 3*F3,
 {{F1, 50}, 0, 100, 1}, {{F2, 50}, 0, 100, 1}, {{F3, 50}, 0, 100, 1}, 
 ControlType -> InputField]

Thanks!

POSTED BY: Thomas B
9 Replies

I'd start with something like this:

Manipulate[Column[{x, 2 x, 3 x}], {{x, 0}, ControlType -> InputField},
 Row[{"2x ", InputField[Dynamic[2 x, (x = 1/2 #) &]]}],
 Row[{"3x ", InputField[Dynamic[3 x, (x = 1/3 #) &]]}]]
POSTED BY: John Fultz
Posted 8 years ago

That works perfectly! Thank you! I just don't understand why it works

POSTED BY: Thomas B

What part of "it's magic" are you not understanding?

POSTED BY: Daniel Lichtblau
Posted 8 years ago

This line:

Dynamic[2 x, (x = 1/2 #) &]

POSTED BY: Thomas B

I was not being serious-- I don't really understand this stuff either. But I took a look at the documentation for Dynamic and that does make this more or less clear. Dynamic[2 x, (x = 1/2 #) &] will tie the first argument to 2x, as you want. It also applies the second argument when you update the current expression in this input field. That second argument has the effect of resetting x which is again what you want.

POSTED BY: Daniel Lichtblau

Try this:

Manipulate[Text[
Row[{"F1 = ", F1, "; F2 = ", F2, "; F3 = ", F3}]], 
{{upd, 1, "update"}, {1 -> "F1", 2 -> "F2", 3 -> "F3"}, Setter},
{{F, 1, "F"}, 1, 10}, TrackedSymbols :> {upd, F}, 
Initialization :> (F1 :=  F/upd; F2 := 2 F/upd; F3 := 3 F/upd;)]
POSTED BY: S M Blinder
Posted 8 years ago

Also very useful, thank you!

POSTED BY: Thomas B

It appears like you really have only one independent input variable, say F1. Then define F2:=(1/2)F1 and F3:=(1/3)F1.

POSTED BY: S M Blinder
Posted 8 years ago

I tried that. The problem that I ran into is that if I update F1, the other two will update but if I update either of the other two, F1 will not update. It seems like the equal sign is a one way assignment and does not work backwards.

Also := seems to break it for some reason, regular equal sign works.

POSTED BY: Thomas B
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