Platform
Resources
Pricing
Sign in
Get started
Harry Stevens
News and graphics at @ClimateLab, a project of @PostGraphics.
Workspace
Fork
Public
Math
By
Harry Stevens
Edited
Sep 18, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
heads_flip
=
binompdf
(
1
,
// number of flips
0.5
,
// probability of heads
1
// number of heads
)
Insert cell
Insert cell
Insert cell
heads_n_in_a_row
=
binompdf
(
n
,
// number of flips
0.5
,
// probability of heads,
n
// number of heads
)
Insert cell
Insert cell
Plot
.
plot
(
{
height
:
300
,
marks
:
[
Plot
.
barY
(
d3
.
range
(
1
,
11
)
.
map
(
n
=>
(
{
n
,
p
:
binompdf
(
n
,
0.5
,
n
)
}
)
)
,
{
y
:
"p"
,
x
:
"n"
,
fill
:
"steelblue"
,
tip
:
true
}
)
]
}
)
Insert cell
Insert cell
Insert cell
binompdf
(
1
,
// number of years
0.01
,
// probability of flood in a given year
1
// number of floods
)
Insert cell
Insert cell
p_1_100_year_flood
=
binompdf
(
100
,
// number of years
0.01
,
// probability of flood in a given year
1
// number of floods
)
Insert cell
Insert cell
Insert cell
Insert cell
p_0_100_year_flood
=
binompdf
(
100
,
// number of years
0.01
,
// probability of flood in a given year
0
// number of floods
)
Insert cell
Insert cell
Insert cell
Plot
.
plot
(
{
height
:
300
,
marks
:
[
Plot
.
barY
(
d3
.
range
(
7
)
.
map
(
f
=>
(
{
f
,
p
:
binompdf
(
100
,
0.01
,
f
)
}
)
)
,
{
y
:
"p"
,
x
:
"f"
,
fill
:
"steelblue"
,
tip
:
true
}
)
]
}
)
Insert cell
binompdf
=
(
n
,
p
,
x
)
=>
{
return
combination
(
n
,
x
)
*
Math
.
pow
(
p
,
x
)
*
Math
.
pow
(
1
-
p
,
n
-
x
)
;
}
Insert cell
combination
=
(
n
,
r
)
=>
{
return
factorial
(
n
)
/
(
factorial
(
n
-
r
)
*
factorial
(
r
)
)
;
}
Insert cell
factorial
=
r
=>
{
let
o
=
1
;
const
a
=
Math
.
abs
(
r
)
,
s
=
r
===
0
?
1
:
Math
.
sign
(
r
)
;
if
(
a
>
1
)
{
o
=
a
;
let
i
=
a
-
1
;
while
(
i
>=
1
)
{
o
*=
i
--
;
}
}
return
o
*
s
;
}
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
heads_flip
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
n
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
heads_n_in_a_row
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
p_1_100_year_flood
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
p_0_100_year_flood
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
binompdf
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
combination
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
factorial
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML