sum2mat {lazy.symbolic} | R Documentation |
Express Summation Expressions in Matrix Form
Description
Express Summation Expressions in Matrix Form
Usage
sum2mat(sexpr, expand = 1, print = 1, debug = 0)
Arguments
sexpr |
input summation expression |
expand |
= 0 not to expand the input prior to processing |
print |
= 0 not to print the result |
debug |
= 1 to print debug info |
Details
The summation of an expression over subscript k is expressed as
s( exp, {sub} )
or
s( exp, {sub, from, to} )
However, in this function,
it is assumed that the subscript must be the abbreviated form {sub}
not the full form {sub,from,to}.
The body part of sum must have only one term: Compare the following:
sum2mat("s(a+b,{k})", expand=0)
and
sum2mat("s(a+b,{k})"
where the default expand=1
option expands the body of a summation.
When there are multiple summations in an expression,
use sumMoveIn
prior to the call. See the last example below.
If you have trouble with handling t
and diag
,
replace t(X)
by "tX_", and diag(X)
by "dX_", resp.
(Double byte t and d with trailing single byte underscore _.)
When the input expression is complex , the result may NOT be correct!!
Value
Corresponding matrix expression with subscripts
Examples
sexpr="s(A[i,j]*b[j],{j})" |> sum2mat()
sexpr="s(A[j,i]*b[j],{j})" |> sum2mat()
sexpr="s(b[i]*A[i,j],{i})" |> sum2mat()
sexpr="s(b[j]*A[i,j],{j})" |> sum2mat()
sexpr="s(A[i,k]*B[k,j],{k}) + s(A[i,k]*B[j,k],{k})" |> sum2mat()
sexpr="s(A[k,i]*B[k,j],{k}) + s(A[k,i]*B[j,k],{k})" |> sum2mat()
sexpr="s(A[i,k]*B[k,j] + A[i,k]*B[j,k],{k})" |> sum2mat()
sexpr="A[i,j]" |> sum2mat()
sexpr="A[i,j]*D[j,j]" |> sum2mat()
sexpr="A[i,j]*D[i,i]" |> sum2mat()
sexpr="D[i,i]*A[i,j]" |> sum2mat()
sexpr="A[i,j]+B[i,j]" |> sum2mat()
sexpr="-A[i,j]-B[i,j]+C[i,j]" |> sum2mat()
sexpr="s(A[i,j],{j})" |> sum2mat()
sexpr="s(A[i,j],{i})" |> sum2mat()
sexpr="s(A[i,j]*D[j,j],{j})" |> sum2mat()
sexpr="s(s(A[i,j]*B[j,k],{k}),{j})" |> sum2mat()
sexpr="s(s(A[i,j]*B[j,k],{k}),{j})" |> sumMoveIn() |> sum2mat()