Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Plotting graphics with For[...]' topicStudent Support Forum > General > Archives > "Plotting graphics with For[...]"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
yehuda
08/28/12 5:13pm

With Mathematica ALWAYS remember that everything is an expression, and each expression returns a value. expressions that do not return values actually return the value Null representing that they do not return values.
using procedural programming style involves loops
For loop and Do loop do not return values
Table returns values
Therefore
For[....,ANY KIND of expression]
returns Null, and also if the expression is graphical in nature the enclosing For (or Do) loop returns Null and you will not see any graphical result NOR get any answer in return

so, If you want to have a set graphics you need to use Table
another option is to use a function with side effects, meaning that it returns Null (or some other values) but with a byproduct of generating your Graphics, but without having its value

Do[Plot[Sin[n t],{t,0,2Pi}],{n,1,3}]
returns nothing
For[n=1,n<4,n++,Plot[Sin[n t],{t,0,2Pi}]]
returns nothing
Table[Plot[Sin[n t],{t,0,2Pi}],{n,1,3}]
returns a list of graphic objects

Do[Print[Plot[Sin[n t],{t,0,2Pi}]],{n,1,3}]
will print each graphics in a different cell, you do not have the values
Do[g[n]=Plot[Sin[n t],{t,0,2Pi}],{n,1,3}]
assigns the first graphics to g[1] etc. and you can use them later

now choose the solution you need

HTH
yehuda

URL: ,

Subject (listing for 'Plotting graphics with For[...]')
Author Date Posted
Plotting graphics with For[...] Mauricio Per... 08/27/12 12:43pm
Re: Plotting graphics with For[...] Bill Simpson 08/28/12 4:53pm
Re: Plotting graphics with For[...] yehuda 08/28/12 5:13pm
Re: Plotting graphics with For[...] Nasser M. Ab... 08/28/12 11:05pm
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic