diff options
| Commit | f9f9c56d32d6698fad46ad8192a020336bc618f6 (patch) | |
|---|---|---|
| Author | 2024-04-16 13:20:47 +0300 | |
| Committer | 2024-04-16 13:20:47 +0300 | |
| Files | 48fb6a8a89c4722c1b72ba0a20aae4a2d4103b29 | |
| uni-projects-f9f9c56d32d6698fad46ad8192a020336bc618f6.tar uni-projects-f9f9c56d32d6698fad46ad8192a020336bc618f6.tar.gz uni-projects-f9f9c56d32d6698fad46ad8192a020336bc618f6.zip | ||
| Parent | a1ddf90dd755b7e862882bd7304ecccd228a1712 (diff) | |
[S/hw1] Code formatting improvements and added rounding to ex1
3 files changed, 11 insertions, 8 deletions
| -rw-r--r-- | Year 3/Statistics/hw1.pdf | bin | 78116 -> 86324 bytes | |||
| -rw-r--r-- | Year 3/Statistics/hw1.r | 17 | ||||
| -rw-r--r-- | Year 3/Statistics/hw1.tex | 2 |
diff --git a/Year 3/Statistics/hw1.pdf b/Year 3/Statistics/hw1.pdf Binary files differindex dd012be..10bb24a 100644 --- a/Year 3/Statistics/hw1.pdf +++ b/Year 3/Statistics/hw1.pdf diff --git a/Year 3/Statistics/hw1.r b/Year 3/Statistics/hw1.r index 3112182..ec9f021 100644 --- a/Year 3/Statistics/hw1.r +++ b/Year 3/Statistics/hw1.r @@ -6,30 +6,33 @@ ex1 <- function(total = 24, marked = 4, boxes = 4, iterations = 10000) { apples <- sample(append(rep("marked", each=marked), rep("normal", each=total - marked))) current <- 0 - for (b in 1:boxes) { - current <- current + (sum(apples[1:perbox + (b-1)*perbox] == "marked") == 1) + for (b in 0:boxes-1) { + current <- current + (1 == sum(apples[1:perbox + b*perbox] == "marked")) } successes <- successes + (current == 4) } - return (successes / iterations) + return (round(successes / iterations, digits=2)) } ex1() ex2 <- function(n, lambda = 1/5, N = 10000, mu = 5, sigma = 5 / sqrt(n)) { - xdash <- replicate(N, sum(rexp(n, rate=lambda)) / n) + x <- function() rexp(n, rate=lambda) + xdash <- replicate(N, sum(x()) / n) fchapeau <- function(t) { - return (1 / N * sum(xdash <= t)) + # I е излишна на практика, но гледам да следвам условието възможно най-стриктно + I <- function(a) as.integer(a == TRUE) + return (1/N * sum(I(xdash <= t))) } t <- seq(0, 10, by=0.1) Fpoints <- sapply(t, fchapeau) - Npoints <- sapply(t, function(t) { return (dnorm(t, mu, sigma)) }) + Npoints <- sapply(t, function(t) dnorm(t, mu, sigma)) - plot(t, Fpoints, type="l", ylim=c(0, 1.1)) + plot (t, Fpoints, type="l", ylim=c(0, 1.1)) lines(t, Npoints, lty=2) } diff --git a/Year 3/Statistics/hw1.tex b/Year 3/Statistics/hw1.tex index 0f5af15..308b642 100644 --- a/Year 3/Statistics/hw1.tex +++ b/Year 3/Statistics/hw1.tex @@ -62,7 +62,7 @@ \lstinputlisting[language=R, firstline=1, lastline=19, caption=Сорс-код]{hw1.r} \begin{lstlisting}[language=R, caption=Получен резултат] -[1] 0.1238 +[1] 0.12 \end{lstlisting} Вероятността във всяка кутия да има по една червива ябълка е приблизително 12\%. |
