f(p)=c p3(1-p)7
Let's plot it, in S-Plus and also in Mathematica, in several ways, usually with c=1.
First, S-Plus; start it within Emacs or, for command-line die-hards, try "Splus -e" from the command line. Then, once S-Plus is running, type or cut-and-paste:
motif(); # Under Windows, use "graph.sheet();" instead help.start(); # Nicer, windowed help system p <- seq(0,1,,101); # Or (0:100)/100; or seq(0,1,.01); or ... f <- p^3 * (1-p)^7; # Or dbinom(3,10,p); or dbeta(p,4,8); or ... plot(p,f,type="l"); # Try adding ",lwd=3" or ",col=3" or ... # or ',xlab="Probability"' or "help(plot)" f <- function(p) { p^3 * (1-p)^7; } # Redefinition of f: now f is a FUNCTION plot(p,f(p),type="l",col=3,xlab="Prob",ylab="Density"); title("Example"); text(.5,.7*max(f(p)), "Lab 2"); # Text, anywhere you want it mean(f(runif(10000,0,1))); # Monte Carlo approximate integration sum(f(p))/101; # Quadrature approximate integration pbeta(.01,4,8); # What's the probability that p<0.01 ? q(); # Done!
Try each of "p^3 * (1-p)^7", "dbinom(3,10,p)", "dbeta(p,4,8)" for f; do you notice any differences? Try removing the 'type="l"', or replacing it with type "b" or "s" or "o". Try adding "lty=2" or "lty=3". These are described (with WAY too many other options) if you try "?par". Try varying the number of Monte Carlo samples or the size of the quadrature mesh. Do you know what the exact integral is? You soon will...
Now let's try Mathematica. To begin a mathematica session simply type "math"; on ACPUB, mathematica will respond with its input prompt "In[1]:=". Remember, you need to end each line with a SHIFT RETURN to make Mathematica execute the line.
Plot[p^3 (1-p)^7, {p,0,1}] (* Try replacing p with x *) f[p_] := p^3 * (1-p)^7 (* This defines a function in Mathematica *) Plot[ f[p], {p,0,1} ] (* Note square brackets for func args *) Display["myfile.ps",%] (* Copies plot to postscript file *) (* From another window you can print it *) Display["!lpr -Psoclp2",%] (* Prints directly to printer soclp2 *) ?FindMinimum (* HELP! *) FindMinimum[-f[p], {p,.5}] (* There is no "FindMaximum" command *) D[f[p],p] (* Derivatives are easy *) D[Log[f[p]],p] Solve[ D[f[p],p]==0, p ] (* Note all ten solutions are given *) Integrate[f[p],{p,0,1}] (* Compare to the MC and Quad answers above *) N[%] (* Numerical answers are always available too *) Integrate[f[p],{p,0,0.01}]/Integrate[f[p],{p,0,1.0}] (* What's the probability that p<0.01 ? *) Quit (* Done! *)
In Mathematica, you can indicate multiplication EITHER by an asterisk ("7*3") or just by juxtaposition ("7 3").
Many problems can be solved with EITHER S-Plus OR Mathematica; each has its advantages.