Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 66 characters in body
Source Link
ovs
  • 61.2k
  • 3
  • 49
  • 164

APL(Dyalog Unicode), (削除) (削除ここまで)38 bytes SBCS

Takes r on the left and s on the right and returns a complex number.

{(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}

Try it on APLgolf!

Uses the first approach presented in the question. Dyalog doesn't have a builtin for sampling from a normal distribution, so this uses the Box–Muller transform to convert to random numbers from \$(0,1)\$ to a normally distributed value:

(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0) draws a normally distributed value \$b \sim N(\alpha, \omega^2)\$:
?0 random number \$c \in (0,1)\$
1しろまるしろまる×ばつ?0: \$\sin(2\pi c)\$
?0 random number \$d \in (0,1)\$
.5*⍨ ×ばつ⍟?0: \$\sqrt{-2\ln{d}}\$
×ばつ Scale from \$N(0, 1)\$ to \$N(\alpha, \omega^2)\$

?0 generates a random number \$a \in (0,1)\$
̄12しろまる×ばつしろまる?0: \$e^{i 2\pi a} = \sin(2\pi a)i + cos(2\pi a)\$

The product of these two values is the result.

Plotting code and images:

'InitCauseway' ⎕CY 'sharpplot'
InitCauseway ⍬
sp←⎕NEW Causeway.SharpPlot(700)
sp.SetTrellis(2 2)
sp.TrellisStyle←4
F ← {(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}
:For r s :In (1 0.1)(3 1)(1 0)(100 5)
 sp.NewCell
 sp.Heading←'r = ',(⍕r),'; s = ',⍕s
 sp.SetAxesScales(1)
 sp.DrawScatterPlot↓9 11∘.しろまる{r F s} ̈⍳1000
:EndFor
sp.SaveSvg(⊂'plot.svg')

enter image description here

APL(Dyalog Unicode), (削除) (削除ここまで)38 bytes SBCS

Takes r on the left and s on the right and returns a complex number.

{(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}

Try it on APLgolf!

Uses the first approach presented in the question. Dyalog doesn't have a builtin for sampling from a normal distribution, so this uses the Box–Muller transform to convert to random numbers from \$(0,1)\$ to a normally distributed value.

Plotting code and images:

'InitCauseway' ⎕CY 'sharpplot'
InitCauseway ⍬
sp←⎕NEW Causeway.SharpPlot(700)
sp.SetTrellis(2 2)
sp.TrellisStyle←4
F ← {(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}
:For r s :In (1 0.1)(3 1)(1 0)(100 5)
 sp.NewCell
 sp.Heading←'r = ',(⍕r),'; s = ',⍕s
 sp.SetAxesScales(1)
 sp.DrawScatterPlot↓9 11∘.しろまる{r F s} ̈⍳1000
:EndFor
sp.SaveSvg(⊂'plot.svg')

enter image description here

APL(Dyalog Unicode), (削除) (削除ここまで)38 bytes SBCS

Takes r on the left and s on the right and returns a complex number.

{(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}

Try it on APLgolf!

Uses the first approach presented in the question. Dyalog doesn't have a builtin for sampling from a normal distribution, so this uses the Box–Muller transform to convert to random numbers from \$(0,1)\$ to a normally distributed value:

(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0) draws a normally distributed value \$b \sim N(\alpha, \omega^2)\$:
?0 random number \$c \in (0,1)\$
1しろまるしろまる×ばつ?0: \$\sin(2\pi c)\$
?0 random number \$d \in (0,1)\$
.5*⍨ ×ばつ⍟?0: \$\sqrt{-2\ln{d}}\$
×ばつ Scale from \$N(0, 1)\$ to \$N(\alpha, \omega^2)\$

?0 generates a random number \$a \in (0,1)\$
̄12しろまる×ばつしろまる?0: \$e^{i 2\pi a} = \sin(2\pi a)i + cos(2\pi a)\$

The product of these two values is the result.

Plotting code and images:

'InitCauseway' ⎕CY 'sharpplot'
InitCauseway ⍬
sp←⎕NEW Causeway.SharpPlot(700)
sp.SetTrellis(2 2)
sp.TrellisStyle←4
F ← {(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}
:For r s :In (1 0.1)(3 1)(1 0)(100 5)
 sp.NewCell
 sp.Heading←'r = ',(⍕r),'; s = ',⍕s
 sp.SetAxesScales(1)
 sp.DrawScatterPlot↓9 11∘.しろまる{r F s} ̈⍳1000
:EndFor
sp.SaveSvg(⊂'plot.svg')

enter image description here

deleted 66 characters in body
Source Link
ovs
  • 61.2k
  • 3
  • 49
  • 164

APL(Dyalog Unicode), (削除) (削除ここまで)38 bytes SBCS

Takes r on the left and s on the right and returns a complex number.

{(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}

Try it on APLgolf!

Uses the first approach presented in the question. Dyalog doesn't have a builtin for sampling from a normal distribution, so this uses the Box–Muller transform to convert to random numbers from \$(0,1)\$ to a normally distributed value.

Plotting code and images:

'InitCauseway' ⎕CY 'sharpplot'
InitCauseway ⍬
F ← {(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}
∇ rs Plot ss;x;y;sp;r;s
 sp←⎕NEW Causeway.SharpPlot(700)
sp.SetTrellis(2 2)
sp.TrellisStyle←4
F  {(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}
:For r s :In ↓⍉↑rs(1 ss
0.1)(3 1)(1 0)(100 5)
 sp.NewCell
 sp.Heading←'r = ',(⍕r),'; s = ',⍕s
 sp.SetAxesScales(1)
 sp.DrawScatterPlot↓9 11∘.しろまる{r F s} ̈⍳1000
:EndFor
sp.SaveSvg(⊂'plot.svg')
∇
1 3 1 100 Plot 0.1 1 0 5

enter image description here

APL(Dyalog Unicode), (削除) (削除ここまで)38 bytes SBCS

Takes r on the left and s on the right and returns a complex number.

{(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}

Try it on APLgolf!

Uses the first approach presented in the question. Dyalog doesn't have a builtin for sampling from a normal distribution, so this uses the Box–Muller transform to convert to random numbers from \$(0,1)\$ to a normally distributed value.

Plotting code and images:

'InitCauseway' ⎕CY 'sharpplot'
InitCauseway ⍬
F ← {(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}
∇ rs Plot ss;x;y;sp;r;s
 sp←⎕NEW Causeway.SharpPlot(700)
sp.SetTrellis(2 2)
sp.TrellisStyle←4
 :For r s :In ↓⍉↑rs ss
 sp.NewCell
 sp.Heading←'r = ',(⍕r),'; s = ',⍕s
 sp.SetAxesScales(1)
 sp.DrawScatterPlot↓9 11∘.しろまる{r F s} ̈⍳1000
:EndFor
sp.SaveSvg(⊂'plot.svg')
∇
1 3 1 100 Plot 0.1 1 0 5

enter image description here

APL(Dyalog Unicode), (削除) (削除ここまで)38 bytes SBCS

Takes r on the left and s on the right and returns a complex number.

{(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}

Try it on APLgolf!

Uses the first approach presented in the question. Dyalog doesn't have a builtin for sampling from a normal distribution, so this uses the Box–Muller transform to convert to random numbers from \$(0,1)\$ to a normally distributed value.

Plotting code and images:

'InitCauseway' ⎕CY 'sharpplot'
InitCauseway ⍬
sp←⎕NEW Causeway.SharpPlot(700)
sp.SetTrellis(2 2)
sp.TrellisStyle←4
F  {(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}
:For r s :In (1 0.1)(3 1)(1 0)(100 5)
 sp.NewCell
 sp.Heading←'r = ',(⍕r),'; s = ',⍕s
 sp.SetAxesScales(1)
 sp.DrawScatterPlot↓9 11∘.しろまる{r F s} ̈⍳1000
:EndFor
sp.SaveSvg(⊂'plot.svg')

enter image description here

deleted 1 character in body
Source Link
ovs
  • 61.2k
  • 3
  • 49
  • 164

APL(Dyalog Unicode), (削除) (削除ここまで)38 bytes SBCS

Takes r on the left and s on the right and returns a complex number.

{(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}

Try it on APLgolf!

Uses the first approach presented in the question. Dyalog doesn't have a builtin for sampling from a normal distribution, so this uses the Box–Muller transform to convert to random numbers from \$(0,1)\$ to a normally distributed value.

Plotting code and images:

'InitCauseway' ⎕CY 'sharpplot'
InitCauseway ⍬
F ← {(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}
∇ {fname}←rrs Plot s;x;y;spss;x;y;sp;r;s
 sp←⎕NEW Causeway.SharpPlot(300700)
 300 sp.SetTrellis(2 2)
 sp.TrellisStyle←4
 :For r s :In ↓⍉↑rs ss
 sp.NewCell
 sp.Heading←'r = ',(⍕r),'; s = ',⍕s
 sp.SetAxesScales(1)
 sp.DrawScatterPlot ↓9DrawScatterPlot↓9 11∘.しろまる{r F s} ̈⍳1000
 :EndFor
 sp.SaveSvg(⊂fname←'plot',(⍕r),'_',(⍕s),'⊂'plot.svg')
∇
u←11 3 1 100 Plot ̈Plot 0.1 1 0 5
⍝ Run in shell: montage plot*.svg -geometry +2+2 out.png
⎕NDELETE ̈u ⍝ Delete single plots

sample distributions enter image description here

APL(Dyalog Unicode), (削除) (削除ここまで)38 bytes SBCS

Takes r on the left and s on the right and returns a complex number.

{(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}

Try it on APLgolf!

Uses the first approach presented in the question. Dyalog doesn't have a builtin for sampling from a normal distribution, so this uses the Box–Muller transform to convert to random numbers from \$(0,1)\$ to a normally distributed value.

Plotting code and images:

'InitCauseway' ⎕CY 'sharpplot'
InitCauseway ⍬
F ← {(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}
∇ {fname}←r Plot s;x;y;sp
 sp←⎕NEW Causeway.SharpPlot(300 300)
 sp.Heading←'r = ',(⍕r),'; s = ',⍕s
 sp.SetAxesScales(1)
 sp.DrawScatterPlot ↓9 11∘.しろまる{r F s} ̈⍳1000
 sp.SaveSvg(⊂fname←'plot',(⍕r),'_',(⍕s),'.svg')
∇
u←1 3 1 100 Plot ̈ 0.1 1 0 5
⍝ Run in shell: montage plot*.svg -geometry +2+2 out.png
⎕NDELETE ̈u ⍝ Delete single plots

sample distributions

APL(Dyalog Unicode), (削除) (削除ここまで)38 bytes SBCS

Takes r on the left and s on the right and returns a complex number.

{(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}

Try it on APLgolf!

Uses the first approach presented in the question. Dyalog doesn't have a builtin for sampling from a normal distribution, so this uses the Box–Muller transform to convert to random numbers from \$(0,1)\$ to a normally distributed value.

Plotting code and images:

'InitCauseway' ⎕CY 'sharpplot'
InitCauseway ⍬
F ← {(×ばつ(.5*⍨ ×ばつ⍟?0)×ばつ1しろまるしろまる×ばつ?0)×ばつ ̄12しろまる×ばつしろまる?0}
∇ rs Plot ss;x;y;sp;r;s
 sp←⎕NEW Causeway.SharpPlot(700)
  sp.SetTrellis(2 2)
 sp.TrellisStyle←4
 :For r s :In ↓⍉↑rs ss
 sp.NewCell
 sp.Heading←'r = ',(⍕r),'; s = ',⍕s
 sp.SetAxesScales(1)
 sp.DrawScatterPlot↓9 11∘.しろまる{r F s} ̈⍳1000
 :EndFor
 sp.SaveSvg(⊂'plot.svg')
∇
1 3 1 100 Plot 0.1 1 0 5

enter image description here

added 369 characters in body
Source Link
ovs
  • 61.2k
  • 3
  • 49
  • 164
Loading
Source Link
ovs
  • 61.2k
  • 3
  • 49
  • 164
Loading

AltStyle によって変換されたページ (->オリジナル) /