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

please send help #3

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

please send help #3

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

Comments

@jocelyn-cuthbert
Copy link
Collaborator

so I am trying to combine the pieces of square function and diamond function and matrix creation.

issue one: I defintely am not actually making a matrix. Its just spitting out the function back at me in black. And with no error. So I am a little lost on where to start in fixing that haha.

issue two: Once I am able to make the matrix without messing everything up, how do I tell it to perform the function on smaller and smaller squares? I'm assuming there needs to be a if statement that if at some point you can't go smaller to break the loop. So can I do the median of the median of the median of y or x until it is = or smaller than 0?

@willpearse
Copy link
Member

Issue one is easy to fix - you're not calling the function, you're just storing it somewhere else. So, instead of writing mat <- diamond_square_step you should be writing mat <- diamond_square_step(). I think you must just be tired, because you definitely know that you need to call a matrix by putting the parentheses in there. Because everything in R is an object, you can take a function and assign it another name - that's what you did in this case.

You're very, very nearly there with the terrain bit! You need to write a loop that will go across all the different mid-points for your matrix. So, in the first iteration, the function will apply your diamond and square steps functions to the entire matrix. Then, in the second iteration, it will apply the diamond and then the square steps to all four sub-matrices. And then, in the third, to all 16 sub-matrices...

There are lots of ways of doing that loop. You could do it with your median of medians method (something like median(1:nrow(mat) and then median(1:median) and median(median:nrow(mat)) I suppose. Or you could write a loop that went across all the different possible sizes by using the seq function and its by argument. So something like seq(1,9,by=8) and then seq(1,9,by=4) and then ... make sense?

@jocelyn-cuthbert
Copy link
Collaborator Author

errrr I really really broke it trying to make an adjustable by

Error in ncol(mat) : could not find function "i" In addition: Warning messages:
1: In if (n < 0L) stop("wrong sign in 'by' argument") :
the condition has length > 1 and only the first element will be used
2: In if (n > .Machine$integer.max) stop("'by' argument is much too small") :
the condition has length > 1 and only the first element will be used
3: In 0L:n : numerical expression has 2 elements: only the first used
4: In if (by > 0) pmin(x, to) else pmax(x, to) :
the condition has length > 1 and only the first element will be used
5: In if (n < 0L) stop("wrong sign in 'by' argument") :
the condition has length > 1 and only the first element will be used
6: In if (n > .Machine$integer.max) stop("'by' argument is much too small") :
the condition has length > 1 and only the first element will be used
7: In 0L:n : numerical expression has 2 elements: only the first used
8: In if (by > 0) pmin(x, to) else pmax(x, to) :
the condition has length > 1 and only the first element will be used

@jocelyn-cuthbert
Copy link
Collaborator Author

on a related note.....https://xkcd.com/1739/

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