mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-26 17:54:22 +01:00
Move all files
This commit is contained in:
13
M1/Monte Carlo Methods/Monte Carlo Methods.Rproj
Normal file
13
M1/Monte Carlo Methods/Monte Carlo Methods.Rproj
Normal file
@@ -0,0 +1,13 @@
|
||||
Version: 1.0
|
||||
|
||||
RestoreWorkspace: Default
|
||||
SaveWorkspace: Default
|
||||
AlwaysSaveHistory: Default
|
||||
|
||||
EnableCodeIndexing: Yes
|
||||
UseSpacesForTab: Yes
|
||||
NumSpacesForTab: 2
|
||||
Encoding: UTF-8
|
||||
|
||||
RnwWeave: Sweave
|
||||
LaTeX: pdfLaTeX
|
||||
25
M1/Monte Carlo Methods/TP1-Test.rmd
Normal file
25
M1/Monte Carlo Methods/TP1-Test.rmd
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
title: "R Notebook"
|
||||
output: html_document
|
||||
---
|
||||
|
||||
The [R plugin](https://www.jetbrains.com/help/pycharm/r-plugin-support.html) for IntelliJ-based IDEs provides
|
||||
handy capabilities to work with the [R Markdown](https://www.jetbrains.com/help/pycharm/r-markdown.html) files.
|
||||
To [add](https://www.jetbrains.com/help/pycharm/r-markdown.html#add-code-chunk) a new R chunk,
|
||||
```{r}
|
||||
|
||||
```
|
||||
position the caret at any line or the code chunk, then click "+".
|
||||
|
||||
The code chunk appears:
|
||||
```{r}
|
||||
```
|
||||
|
||||
Type any R code in the chunk, for example:
|
||||
```{r}
|
||||
mycars <- within(mtcars, { cyl <- ordered(cyl) })
|
||||
mycars
|
||||
```
|
||||
|
||||
Now, click the **Run** button on the chunk toolbar to [execute](https://www.jetbrains.com/help/pycharm/r-markdown.html#run-r-code) the chunk code. The result should be placed under the chunk.
|
||||
Click the **Knit and Open Document** to build and preview an output.
|
||||
27
M1/Monte Carlo Methods/TP1.Rmd
Normal file
27
M1/Monte Carlo Methods/TP1.Rmd
Normal file
@@ -0,0 +1,27 @@
|
||||
# Exercice 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)
|
||||
```
|
||||
|
||||
# Exercice 3 : Box Muller Algo
|
||||
|
||||
```{r}
|
||||
BM <- function(n) {
|
||||
U1 <- runif(n)
|
||||
U2 <- runif(n)
|
||||
X1 <- sqrt(-2 * log(U1)) * cos(2 * pi * U2)
|
||||
X2 <- sqrt(-2 * log(U1)) * sin(2 * pi * U2)
|
||||
return(c(X1, X2))
|
||||
}
|
||||
|
||||
n <- 10e4
|
||||
X <- BM(n)
|
||||
|
||||
hist(X, breaks = 100, freq = FALSE)
|
||||
curve(dnorm(x), add = TRUE, col = "red")
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user