Prev: Find value of unknown const that causes integral to equal some value
Next: Number to string headed by zeros
From: Antonio De Juárez on 12 Jun 2010 05:31 Sometimes, I would find useful a method to update variables automatically. For example, given the delayed rule b:=3 a+1; it would be useful to have b updated whenever a is assigned a new value, like a=37. Is there any method to do this in Mathematica? Thanks, Antonio.
From: Sjoerd C. de Vries on 13 Jun 2010 04:09 Are you kidding us? Using SetDelayed (:=) in the definition of b means the most current value of a are used anytime b is used. Check this: b := a a = 2; b a = 4; b yields 2, then 4. Or try b := a Dynamic[b] and the assign various values to a and see the dynamically displayed value of b changing immediately. By the way: b:=3 a +1 is not a delayed rule. That would be b:>3 a +1 Cheers -- Sjoerd On Jun 12, 11:31 am, Antonio De Ju=E1rez <adejua...(a)gmail.com> wrote: > Sometimes, I would find useful a method to update variables > automatically. For example, given the delayed rule > > b:=3 a+1; > > it would be useful to have b updated whenever a is assigned a new > value, like a=37. Is there any method to do this in Mathematica? > > Thanks, > > Antonio.
From: Peter Pein on 13 Jun 2010 04:11 Am Sat, 12 Jun 2010 09:31:06 +0000 (UTC) schrieb Antonio De Ju=E1rez <adejuarez(a)gmail.com>: > Sometimes, I would find useful a method to update variables > automatically. For example, given the delayed rule > > b:=3 a+1; > > it would be useful to have b updated whenever a is assigned a new > value, like a=37. Is there any method to do this in Mathematica? > > Thanks, > > Antonio. > > Hi Antonio, I'm afraid I do not understand your problem: In[1]:= b:=3 a+1; In[2]:= b Out[2]= 1+3 a In[3]:= a:=123 In[4]:= b Out[4]= 370 As you see, b changes its value as a does.
From: Erik Max Francis on 13 Jun 2010 04:12 Antonio De Ju=E1rez wrote: > Sometimes, I would find useful a method to update variables > automatically. For example, given the delayed rule > > b:=3 a+1; > > it would be useful to have b updated whenever a is assigned a new > value, like a=37. Is there any method to do this in Mathematica? I don't really follow the goal of what you're doing here. Using `:=` for assignment explicitly means that you do _not_ want the right-hand side of the expression evaluated. If `b` depends on `a` then the sensible thing to do here is to make `b` a function: b[a_] := 3 a + 1; and then do the appropriate substitute `b[somethingOrOther]` when the time is right. The only other thing I can think of that you might be trying to get at would be `Dynamic`, which you can look up. Perhaps if you said more about the problem you're trying to solve more generally, people could suggest a more appropriate solution. -- Erik Max Francis && max(a)alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis War is like love, it always finds a way. -- Bertolt Brecht
From: telefunkenvf14 on 13 Jun 2010 04:12 On Jun 12, 4:31 am, Antonio De Ju=E1rez <adejua...(a)gmail.com> wrote: > Sometimes, I would find useful a method to update variables > automatically. For example, given the delayed rule > > b:=3 a+1; > > it would be useful to have b updated whenever a is assigned a new > value, like a=37. Is there any method to do this in Mathematica? > > Thanks, > > Antonio. You could tell Mathematica to treat b as Dynamic: Dynamic[b] b := 3 a + 1; Each time you change a, b now reflects the change. a = 2 a = 3 -RG
|
Next
|
Last
Pages: 1 2 Prev: Find value of unknown const that causes integral to equal some value Next: Number to string headed by zeros |