In following code:
det<-function(M)
{
if (nrow(M) == 2)
{
return(M[1,1]*M[2,2]-M[1,2]*M[2,1])
}
else
{
d<-0
for (i in 1:ncol(M))
{
d<-d+(-1)^(i+1)*M[1][i]*det(M[-1,i])
}
return(d)
}
}
to execute function I determined x<-matrix(c(1:9),nrow=3) when execute the function det(x) I get error: Error in if (nrow(M) == 2) { : argument is of length zero
Aucun commentaire:
Enregistrer un commentaire