Search code examples
rmatrix-multiplication

Simplifying matrix product with one unknown variable


I have to compute a product of 3 matrices D=ABC with:

  • A is a (1x3) matrix,
  • B is a (3x3) matrix,
  • C is a (3x1) matrix (and is equal to A', if it matters)

The result of this product is a simple value, and the calculation is very straightforward in R.

My problem is there is one unknown, namely X, inside A and C, and I would like to get the result as a formula: D = ABD = f(X).

Is there any way I could achieve this with R ?


Solution

  • Define D as shown below where argument B is the square matrix and A is a function of x returning a vector.

    D <- function(B, A) function(x) t(A(x)) %*% B %*% A(x)
    
    # test
    A <- function(x) seq(3) * x
    B <- matrix(1:9, 3)
    Dfun <- D(B, A)
    Dfun(10)
    ## [1] 22800