1
|
14038 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
GROUPS:

# What's the difference between f[x_]= ... and f[x_]:=...

Posted 9 years ago
 thanks
2 Replies
Sort By:
Posted 9 years ago
 yes there is, the := notation reevaluates the right-hand-side each time it is evaluated. So there is a difference between these two definitions: ClearAll[p,f] p=2; f[x_]:=x+p; p=3; f[2] ClearAll[p,f] p=2; f[x_]=x+p; p=3; f[2] 
Posted 9 years ago
 RandomInteger[10] is a command that produces a random number from 0 to 10. Evaluate RandomInteger[10] a bunch of times till you have a feel for what it does. Now evaluate this command: myRandomNumber = RandomInteger[10]  Play around with myRandomNumber. How does myRandomNumber behave? myRandomNumber is always the same number. The right hand side of the equal sign was evaluated once and became the value for myRandomNumber. Now evaluate this command: myOtherRandomNumber := RandomInteger[10]  Play around with myOtherRandomNumber. How does it behave? myOtherRandomNumber is always a different number. The right hand side of the equal sign re-evaluates every time you call myOtherRandomNumber.