Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help from people smarter than me #4

Open
jocelyn-cuthbert opened this issue Nov 17, 2016 · 3 comments
Open

help from people smarter than me #4

jocelyn-cuthbert opened this issue Nov 17, 2016 · 3 comments

Comments

@jocelyn-cuthbert
Copy link
Collaborator

my code:
Diamond_square_step_dont_fail <- function(mat,n){
i <- (2^n)-1
j <- (2^n)-1
mat <- mat_function (n)
mat <- square_step (mat,n)
mat <- diamond_step (mat,n)
for (k in 2^(n:1)-1)
for (i in seq(from=1, to=(ncol(mat)), by=k-1)){
for (j in seq(from=1, to=(nrow(mat)), by=k-1)){
mat[j:(j+k-1), i:(i+k-1)] <- square_step(mat[j:(j+k-1), i:(i+k-1)],n)
mat[j:(j+k-1), i:(i+k-1)] <- diamond_step(mat[j:(j+k-1), i:(i+k-1)],n)
}
}
return(mat)
}

was inspired by Alex Regos code
dss <- function(n, sd){
mat <- genmat(n)
side <- (2^n)+1
sd <- sd
for(k in 2^(n:1)){
for(i in seq(1,side-1,by=k)){
for(j in seq(1,side-1,by=k)){
mat[j:(j+k),i:(i+k)] <- d.s(mat[j:(j+k),i:(i+k)],sd)
mat[j:(j+k),i:(i+k)] <- s.s(mat[j:(j+k),i:(i+k)],sd)
}
}
sd <- abs(sd/1.5)
}
return(mat)
}

Mine still doesn't work but you know.....I feel better about it

@willpearse
Copy link
Member

I would advise you to comment on the lines you've pasted in from your code to show that you understand what each is doing

@jocelyn-cuthbert
Copy link
Collaborator Author

Diamond_square_step_dont_fail <- function(mat,n){
#defining i and j so that the grid has defined odd sides. This was an attempt to bypass the issues I was having with only being able to get grids for 5 and 9 length.
i <- (2^n)-1
j <- (2^n)-1
#creating a matrix
mat <- mat_function (n)
#applying my square step
mat <- square_step (mat,n)
#applying my diamond step
mat <- diamond_step (mat,n)
#defining my by variable as something that will change as it loops. So if n was two, this would give me by 4,2,1 all minus one, to keep it within the dimensions of the matrix. so 3 and 1.
for (k in 2^(n:1)-1)
#defining my i and j again. I know I only need to do it once, I am trying still to figure out which is correct
for (i in seq(from=1, to=(ncol(mat)), by=k-1)){
for (j in seq(from=1, to=(nrow(mat)), by=k-1)){
#Applying my functions across the matrix. Right now it is i or j, 1:j+k-1 which is out of the dimensions because i or j + k would be too large, but it worked when I used it for 5 or 9 again, so I am just trying to figure out that piece.
mat[j:(j+k-1), i:(i+k-1)] <- square_step(mat[j:(j+k-1), i:(i+k-1)],n)
mat[j:(j+k-1), i:(i+k-1)] <- diamond_step(mat[j:(j+k-1), i:(i+k-1)],n)
}
}
return(mat)
}

@willpearse
Copy link
Member

...please do this in your repo...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants