Chapter 1 - An Introduction to Mathematica

Section 1.7 - Basic Programming

For[k=1;z=(x^2),k≤4,k++,z=(z^k)+z;Print[z]]

For[k=1,k≤10,k++,Print[NSum[(1/( n!)),{n,0,k},WorkingPrecision->10]]]

sum=0;
Do[sum=sum+k,{k,1,10}];sum

Sum[k,{k,1,10}]

prod=1;

Do[prod=k prod,{k,1,10}];prod

10!

prod=1;

Do[prod=prod k,{k,1,10}];prod

factorial[n_]:=(prod=1;Do[prod=k prod,{k,1,n}];prod)

factorial[10]

add[n_]:=(sum=0;Do[sum=sum+k,{k,1,n}];sum)

add[10]

quadrant[pt_]:=If[pt[[1]]>0&&pt[[2]]>0,Return[quadrant1],If[pt[[1]]<0&&pt[[2]]>0,Return[quadrant2],If[pt[[1]]<0&&pt[[2]]<0,Return[quadrant3],If[pt[[1]]>0&&pt[[2]]<0,Return[quadrant4],axis]]]]

quadrant[{-3,9}]

quadrant[{0,9}]