[R] RE : Help to solve matrices
Marc Schwartz
marc_schwartz at comcast.net
Wed Jan 31 20:38:53 CET 2007
Justin,
Did you actually run that code? :-)
> a<-array(c(3,4,1),dim=c(3,1))
> b<-a%*%a
Error in a %*% a : non-conformable arguments
I suspect that Amina wants:
a <- array(c(3, 4, 1), dim=c(3, 1))
b <- t(a) %*% a
> solve(b)
[,1]
[1,] 0.03846154
or perhaps:
> solve(crossprod(a))
[,1]
[1,] 0.03846154
Amina, note that %o% is an 'outer' product, not an 'inner' product.
See ?outer and ?"%*%"
HTH,
Marc Schwartz
On Wed, 2007-01-31 at 20:21 +0100, justin bem wrote:
> >a<-array(c(3,4,1),dim=c(3,1))
> >b<-a%*%a
> >solve(b)
>
> amna khan <amnakhan493 at gmail.com> a crit : Sir I am new user of R. I
> am facing problems in solving matrices.
> for example
> >a<-array(c(3,4,1),dim=c(3,1))
> >b<-a%o%a
> >b
>
> , , 1, 1
>
> [,1]
> [1,] 9
> [2,] 12
> [3,] 3
>
> , , 2, 1
>
> [,1]
> [1,] 12
> [2,] 16
> [3,] 4
>
> , , 3, 1
>
> [,1]
> [1,] 3
> [2,] 4
> [3,] 1
> >solve(b)
> Error in solve.default(b) : only square matrices can be inverted
> >solve(b,a)
> Error in solve.default(b, a) : 'b' must be compatible with 'a'
> Sir I request you to help me in this regard.
More information about the R-help
mailing list