title: Returning the inverse matrix from a cached object in R
body: <p>Disclosure: This is from a programming assignment from a Coursera Course called R programming</p>
  
  <p>The assignment is regarding lexical scoping and caching functions that may require a long computation time.  Specifically I am using <code>solve()</code> to find the inverse of a matrix and cache it using a free floating variable.  I am returning an error as described below.</p>
  
  <p>First I stored a function in a variable <code>a&lt;-makeCacheMatrix()</code>Then I run <code>a$set(matrix(1:4,2,2)</code>to store a matrix</p>
  
  <p>When I run <code>cacheSolve(a)</code> I get <code>Error in as.vector(x, mode) : cannot coerce type 'closure' to vector of type 'any'</code></p>
  
  <p>From my understanding I suspect that I might be passing an atomic vector when it requires a matrix but I am not sure how to fix </p>
  
  <p>My code:</p>
  
  <pre><code>makeCacheMatrix &lt;- function(x = matrix()) {
    m&lt;-NULL
    set&lt;-function(y){
    x&lt;&lt;-y
    m&lt;&lt;-NULL
  }
  get&lt;-function() x
  setmatrix&lt;-function(solve) m&lt;&lt;- solve
  getmatrix&lt;-function() m
  list(set=set, get=get,
     setmatrix=setmatrix,
     getmatrix=getmatrix)
  }
  
  cacheSolve &lt;- function(x=matrix(), ...) {
      m&lt;-x$getmatrix()
      if(!is.null(m)){
        message("getting cached data")
        return(m)
      }
      matrix&lt;-x$get
      m&lt;-solve(matrix, ...)
      x$setmatrix(m)
      m
  }
  </code></pre>