mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-14 18:59:59 +01:00
Refactor files
This commit is contained in:
8
M1/Monte Carlo Methods/Exercise1.rmd
Normal file
8
M1/Monte Carlo Methods/Exercise1.rmd
Normal file
@@ -0,0 +1,8 @@
|
||||
# Exercise 1 : Uniform
|
||||
|
||||
```{r}
|
||||
n <- 10e4
|
||||
U <- runif(n)
|
||||
X <- 5 * (U <= 0.4) + 6 * (0.4 < U & U <= 0.6) + 7 * (0.6 < U & U <= 0.9) + 8 * (0.9 < U)
|
||||
barplot(table(X)/n)
|
||||
```
|
||||
11
M1/Monte Carlo Methods/Exercise2.rmd
Normal file
11
M1/Monte Carlo Methods/Exercise2.rmd
Normal file
@@ -0,0 +1,11 @@
|
||||
# Exercise 2 : Exponential distribution and related distributions
|
||||
|
||||
```{r}
|
||||
n <- 10000
|
||||
u <- runif(n)
|
||||
x <- -1/2 * log(1-u)
|
||||
hist(x, breaks = 50, freq = FALSE)
|
||||
curve(dexp(x, rate = 2), add = TRUE, col = "red")
|
||||
|
||||
qqplot(x, rexp(n, rate = 2))
|
||||
```
|
||||
@@ -1,12 +1,3 @@
|
||||
# Exercise 1 : Uniform
|
||||
|
||||
```{r}
|
||||
n <- 10e4
|
||||
U <- runif(n)
|
||||
X <- 5 * (U <= 0.4) + 6 * (0.4 < U & U <= 0.6) + 7 * (0.6 < U & U <= 0.9) + 8 * (0.9 < U)
|
||||
barplot(table(X)/n)
|
||||
```
|
||||
|
||||
# Exercise 3 : Box Muller Algo
|
||||
|
||||
```{r}
|
||||
@@ -23,5 +14,4 @@ X <- BM(n)
|
||||
|
||||
hist(X, breaks = 100, freq = FALSE)
|
||||
curve(dnorm(x), add = TRUE, col = "red")
|
||||
```
|
||||
|
||||
```
|
||||
12
M1/Monte Carlo Methods/Exercise5.rmd
Normal file
12
M1/Monte Carlo Methods/Exercise5.rmd
Normal file
@@ -0,0 +1,12 @@
|
||||
# Exercise 5 : Simulation of Brownian Motion
|
||||
|
||||
```{r}
|
||||
n <- 1:1100
|
||||
brownian <- function (i) {
|
||||
return ((i >= 1 & i <= 100)*(i/100) + (i >= 101 & i <= 110)*(1 + (i - 100)/10) + (i >= 111 & i <= 1110)*(2 + (i - 110)/1000))
|
||||
}
|
||||
t <- brownian(n)
|
||||
W0 <- 0
|
||||
Wt <- W0 + sqrt(t) * rnorm(1100)
|
||||
plot(t, Wt, type = "o")
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
Version: 1.0
|
||||
|
||||
RestoreWorkspace: Default
|
||||
SaveWorkspace: Default
|
||||
AlwaysSaveHistory: Default
|
||||
|
||||
EnableCodeIndexing: Yes
|
||||
UseSpacesForTab: Yes
|
||||
NumSpacesForTab: 2
|
||||
Encoding: UTF-8
|
||||
|
||||
RnwWeave: Sweave
|
||||
LaTeX: pdfLaTeX
|
||||
Reference in New Issue
Block a user