Eval {lazy.symbolic} | R Documentation |
Evaluate Symbolic Matrix after Replacement
Eval(
..exp,
...,
values = NULL,
fullsymb = NULL,
check = 1,
ntogoback = 2,
debug = 0
)
..exp |
A symbolic matrix whose elements are to be evaluated after the replacement. |
... |
Replacement of the form pat1=pat2 |
values |
A character vector consisting of several replacements separated by semicolons. |
fullsymb |
= 1 to treat |
check |
= 0 not to check if the expression is evaluatable. (See below.) |
ntogoback |
n parameter of sys.parent function |
debug |
debug parameter for matReplace |
This function first replaces the elements of pat1 matrix included in exp
with the corresponding elements of pat2 matrix.
Then, if the resulting expression contains numbers only, it evaluates
the result.
See the description of matReplace function for details.
This function does NOT attempt to evaluate the expression
if the result of the replacement has any alphabets.
Therefore, if the expression has a function call, with check=1,
it will not be evaluated.
Use check=0 if you are sure that the resulting expression is valid.
A numeric matrix of the same size as exp
# matrix replacement
A <- demomat(2,2, root="a")
B <- demomat(2,2, root="b")
An <- demomat(2,2)
Bn <- demomat(2,2)*1000
ApB <- Plus(A,B)
ApBn <- Eval(ApB, A=An, B=Bn)
ApBn2 <- Eval(ApB, values=c("A=An; B=Bn") )
Print(ApB, ApBn, An+Bn)
Print(ApBn, ApBn2)
AtB <- matTimes(A,B)
AtBn <- Eval(AtB, A=An, B=Bn)
Print(AtB, AtBn, An%*%Bn)
# scalar replacement
val <- "a=1; b=2; c=3; d=4; e=5"
exp <- "(a+b*c-d)/e"
Eval(exp,values=val)
# matrix replacement: fully symbolic expression
res=Eval("matTimes(t(A),B)"
, A=demomat(2,2), B=demomat(2,2), fullsymb=1)
# Below causes an error.
# Eval(A)