Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Markovketten
- # Funktion
- markov.fun <- function(n, M){
- text1 <- "\nn muss groesser als 0 sein!"
- text2 <- "\nM muss eine quadratische Matrix sein!"
- # n muss < 0 sein
- if(!n > 0) {
- stop(text1)
- }
- # M muss eine quadratische Matrix sein
- if(ncol(M) != nrow(M) || !(is.matrix(M))){
- stop(text2)
- }
- # Funktion fuer eine Matrixpotenz
- E <- eigen(M)
- V <- E$values
- Q <- E$vectors
- res.1 <- Q%*%diag(V^n)%*%t(Q)
- return(res.1)
- }
- # Rekursion
- markov.rek <- function(n, M){
- text1 <- "\nn muss groesser als 0 sein!"
- text2 <- "\nM muss eine quadratische Matrix sein!"
- # n muss < 0 sein
- if(!n > 0) {
- stop(text1)
- }
- # M muss eine quadratische Matrix sein
- if(ncol(M) != nrow(M) || !(is.matrix(M))){
- stop(text2)
- }
- #
- if(n = 0) return(diag(n))
- return(M %*% markov.rek( n-1 , M))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement