I need a help to create function (math) to count some basic operations. Indeed i am a beginner and i don't really know how to do it. My task is to make function, which can value of polynomial from scalar or matrix.
First example polynomial is p1 = 1 + t, second polynomial is p2 = 1+ t + t^2
a <- matrix( c( 2, 0, 0, 1), 2, 2)
p1 <- c( 1, 1)
p2 <- c(1, 1, 1)
My expected results:
The use of a methodical function to calculate the value of a polynomial from a scalar:
math( x1 = p1, x2 = 0)
output: 1
math( x1 = p1, x2 = 2)
output: 3
math( x1 = p2, x2 = 2)
output: 7
math( x1= p2, x2 = 1)
output: 3
The use of a methodical function to calculate the value of a polynomial from a matrix:
math( x1 = p1, x2 = a)
[,1] [,2]
[1,] 3 0
[2,] 0 2
math( x1= p2, x2 = a)
[,1] [,2]
[1,] 7 0
[2,] 0 3