Computerintensive Methoden - Simulation of the lines coalescing

From StatWiki
Jump to: navigation, search
REngine.php: > rpdf<-'/var/www/localhost/htdocs/StatWiki/Rfiles/R/56b1b0ddd518d1954512b1fd34c9658ea93bf817_%i.pdf'
> rpdfno<-0
> rhtml<-''
> rfiles<-'/var/www/localhost/htdocs/StatWiki/Rfiles/R/'
> source('/var/www/localhost/htdocs/StatWiki/Rfiles/R/@.R')
> rout<-'text'
> cat('<!--- Start of program --->\n')
<!--- Start of program --->
> n=3
>
> line = array(dim=c(n,n,n))
> size = array(dim=c(n,n))
> coal = array(dim=c(n))
>
> for (j in 1:n) {
+ 	line[n,j,1] <- j
+ 	size[n,j] <- 1
+ }
>
> for (i in 1:(n-3)) {
+ 	coal <- sample(1:(n-i+1), 2, replace=F)
+ 	coal <- sort(coal)
+ 	for (j in 1:coal[2]-1) {
+ 		for (ii in 1:size[n-i+1,j]) {
+ 			line[n-i,j,ii] <- line[n-i+1,j,ii]
+ 		}
+ 		size[n-i,j] <- size[n-i+1,j]
+ 	}
+ }
Error in 1:size[n - i + 1, j] : argument of length 0
Execution halted
in

n=3

line = array(dim=c(n,n,n)) size = array(dim=c(n,n)) coal = array(dim=c(n))

for (j in 1:n) { line[n,j,1] <- j size[n,j] <- 1 }

for (i in 1:(n-3)) { coal <- sample(1:(n-i+1), 2, replace=F) coal <- sort(coal) for (j in 1:coal[2]-1) { for (ii in 1:size[n-i+1,j]) { line[n-i,j,ii] <- line[n-i+1,j,ii] } size[n-i,j] <- size[n-i+1,j] } }