Message Boards Message Boards

Language for plotting in Mathematica 9

Posted 10 years ago

so i started working for a project on the birthday problem ( those who dont know may refer here: http://mathworld.wolfram.com/BirthdayProblem.html ) I created a table which had all values for the probablity and wanted to plot it . I name the table as t and gave command Plot[t], Mathematica plotted but it was a line plot and i wanted something like the screenshot like .the first in table ( i.e expr 1 in the table) with its value at y and 1 at x, 2nd with value at y and 2 at x and so on. the table has 365 so i cant do manually, please help

Attachments:
POSTED BY: Anvit Garg
6 Replies

Is this what you want? Set d=366 to include possible Feb 29. Table example goes to n=23, can expand to 366.

In[1]:= P2[n_, d_] := 1 - d!/((d - n)! d^n)

In[2]:= P2[23, 366] // N

Out[2]= 0.506323

In[3]:= Do[Print[n, "    ", N[P2[n, 366]]], {n, 1, 23}]

1    0.

2    0.00273224

3    0.00818179

4    0.0163114

5    0.0270621

6    0.0403536

7    0.0560856

8    0.0741386

9    0.0910    0.116645

11    0.140781

12    0.166604

13    0.193929

14    0.22256

15    0.252298

16    0.282941

17    0.314288

18    0.346138

19    0.378295

20    0.41057

21    0.442779

22    0.474751

23    0.506323
POSTED BY: S M Blinder

You want ListPlot or ListLinePlot to plot a table of data values. Plot is for plotting a function.

POSTED BY: David Reiss

Plot[t] is syntactically incorrect and will not display anything. Use

ListLinePlot[t]
POSTED BY: David Reiss
Posted 10 years ago

S M Blinder, I don't think you've got my question I'll write my program for your assistance

f[x_] :=1- 365!/((365-x)!*365^x).   

This program would give the chances for 'x' number of days. This made a table for all probabilities

In[2]:t=Table[1- 365!/((365-x)!*365^x),{x,1,366}].  
out[2]:{0,.......(all the probabilities ) ......,1}
In[3]: Plot[t]

The output instead of what shown in the shot above, showed some random lines What I expected that the first expr I.e.0 in out[2] would have 0 as y coordinate and 1 as x coordinate and the last value would have 1 as y coordinate and 366 as x The above figure shows till 100 but I wanted to expand it till 366

Or I suppose if I write Plot[Do[Print[n," ",N[P2[n,365]]],{n,1,366}]] it'd plot the above figure ?

POSTED BY: Anvit Garg
Posted 10 years ago

I don't have access to Mathematica right now will ListLinePlot give a similar result as the figure above

POSTED BY: Anvit Garg

Yes.

enter image description here

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract