Step 1: declaration of symbolic objects using symmatrix
:
n = 2;
A = symmatrix('A', n);
lambda = symmatrix('lambda', [n,1]);
g = symmatrix('g', [n,1]);
phi = symmatrix('phi', [n,1]);
l = symmatrix('l', [n,1]);
item = symmatrix('i', [n,1]);
Step 2: declaration of equations:
arga = (l.'*(((lambda).*(A * g) + (phi.'*lambda) * (A * g))));
argb = (l.'*(((lambda).*(item) + (phi.'*lambda) * (A * g))));
Step 3: differenciating with respect to lambda: arga
and argb
should work in the same way, as both item
and A*g
are 2x1 vectors. However I cannot run the sum in the parenthesis of the output for sola
due to dimensionality issues:
sola = diff(arga, lambda)
solb = diff(argb, lambda)
Step 4: Moreover, running the example below, sola
and solb
give two different results when substituting item
with a*g
, which should not be the case:
l=[1.2;1.1]
g=[1.9876;1.88]
phi=[1.0987;1.5192]
A=[132 123;1222 124]
item=A * g
Running sola
, I get the following expression, which I now evaluate with the value of the example:
l.'*((eye(2)) .* A*g + kron(phi.', A*g))
same for solb
:
l.'*(kron(phi.', A*g) + (eye(2)) .* l)
ISSUES: I was expecting:
- to be able to execute the sum in the parenthesis in the output of
sola
, - to have the same result of sola and
solb
after the evaluation but that is not the case.
What am I missing?
sola = l.'*(symmatrix(eye(2)) .* A*g + kron(phi.', A*g))
. Now,symmatrix(eye(2)) .* A*g
, is a 2x1 matrix andkron(phi.', A*g)
is a 2x2 matrix therefore if i run(symmatrix(eye(2)) .* A*g + kron(phi.', A*g))
, I get the following error: "Error using symbolic.mixin.symbolicmatrix/engineHelperWrapper - Dimensions do not match." Which makes sense as I cannot sum a vector and a matrix.A*g
which is a 2x1 vector withitem
which is another 2x1 vector having as elementsi
, I getl.'*(kron(phi.', A*g) + symmatrix(eye(2)) .* i)
where both of the addenda are 2x2 matrices and can therefore be summed.