Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Loop doesn't work' topicStudent Support Forum > General > "Loop doesn't work"

< Previous CommentHelp | Reply To Comment | Reply To Topic
Author Comment/Response
Bill Simpson
12/22/12 10:55pm

Code: Short-Version doesn't work:
...
pension = pension*(Risky* Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] + Riskless*Exp[riskfree]) - draw

Long-Version Works:
...
year10 := year9*(Risky*Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] + Riskless*Exp[riskfree]) - draw

The difference between not working and working is = versus :=

= calculates one number now and uses that same number 100 times in your Table.

:= saves then definition of year10 and calculates a new number each time you use year10 in your Table.

Study this and then think how to modify your code.

http://reference.wolfram.com/mathematica/tutorial/ImmediateAndDelayedDefinitions.html

URL: ,

Subject (listing for 'Loop doesn't work')
Author Date Posted
Loop doesn't work Student0002012 12/22/12 07:46am
Re: Loop doesn't work Student0002012 12/22/12 10:15pm
Re: Loop doesn't work Bill Simpson 12/22/12 10:55pm
< Previous CommentHelp | Reply To Comment | Reply To Topic