l =
Hi dominik,
I'm not sure what Problem 1 is refering to.
I think Problem 2 can be explained as follows:
clear all
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('l', [n,1])
We see that the Matlab variables l and item both reference the same symbolic variable.
arga = (l.'*(((lambda).*(A * g) + (phi.'*lambda) * (A * g))))
argb = (l.'*(((lambda).*(item) + (phi.'*lambda) * (A * g))))
In argb, we see that the symbolic l shows up in the expression on the right.
sola = diff(arga, lambda)
solb = diff(argb, lambda)
l=[1.2;1.1] ;
g=[1.9876;1.88] ;
phi=[1.0987;1.5192] ;
A=[132 123;1222 124] ;
Here, item is set to A*g, but item is not a variable in the expression for solb. So setting item here has no affect on the results and because l ~= A*g we get different results for sola and solb.
%item=A * g;
% sola, having removed only the symmatrix comand
Also, I think A*g must be enclosed in parentheses.
l.'*((eye(2)) .* (A*g) + kron(phi.', A*g))
% solb, having removed only the symmatrix comand
l.'*(kron(phi.', A*g) + (eye(2)) .* l)
Maybe the intent was for item to be its own variable
%clear all
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('Q', [n,1])
arga = (l.'*(((lambda).*(A * g) + (phi.'*lambda) * (A * g))));
argb = (l.'*(((lambda).*(item) + (phi.'*lambda) * (A * g))));
sola = diff(arga, lambda)
solb = diff(argb, lambda)
l=[1.2;1.1] ;
g=[1.9876;1.88] ;
phi=[1.0987;1.5192] ;
A=[132 123;1222 124] ;
%item=A * g;
Q = A * g;
% sola, having removed only the symmatrix comand
l.'*((eye(2)) .* (A*g) + kron(phi.', A*g))
% solb, having removed only the symmatrix comand
l.'*(kron(phi.', A*g) + (eye(2)) .* Q)