具有以下矩阵和向量。r中的递归乘以
x<-matrix(c(1,4,7,
2,5,8,
3,6,9), nrow = 3)
w <- c(1,1,1)
res <- c()
什么是乘recursiverly,直到获得结果的愿望和作为例证的最好的方法:
res[1]<-w %*%x[1,]
res[2]<-w %*%x[2,]
res[3]<-w %*%x[3,]
res[4]<-w %*%x[1,]
res[5]<-w %*%x[2,]
sum(res)>1000 #Multiply recursiverly till the sum of the results sum(res) goes further than 1000.
你用“while循环”标记它。这是我的建议。 – Frank
@Frank我知道用“while循环”可以完成,但我不知道如何。你能举个例子告诉我如何去做。 –
它们在每种编程语言中都差不多。以下是一个示例,从https://www.rosettacode.org/wiki/Loops/While#R – Frank