0

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:

  1. to be able to execute the sum in the parenthesis in the output of sola,
  2. to have the same result of sola and solb after the evaluation but that is not the case.

What am I missing?

5
  • 1
    Please improve your question. It is not clear what you are asking, the question is badly formatted and the code is spread out across different parts. Please provide a clear, concise minimum example and ask a clear question. As a note: punctuation helps, I had trouble reading your question as it was not always clear where a new sentence started etc.
    – pschulz
    Commented Apr 4, 2024 at 16:51
  • "I cannot run the sum in the parenthesis of the output for sola due to dimensionality issues" -- could you please post the full error message you get? I don't have the symbolic toolbox available right now, so cannot run the code to see what you're seeing. Commented Apr 4, 2024 at 21:52
  • @CrisLuengo sola = l.'*(symmatrix(eye(2)) .* A*g + kron(phi.', A*g)). Now, symmatrix(eye(2)) .* A*g , is a 2x1 matrix and kron(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. Commented Apr 5, 2024 at 10:14
  • @CrisLuengo On the other hand, if I replace A*g which is a 2x1 vector with item which is another 2x1 vector having as elements i, I get l.'*(kron(phi.', A*g) + symmatrix(eye(2)) .* i) where both of the addenda are 2x2 matrices and can therefore be summed. Commented Apr 5, 2024 at 10:15
  • So you found a bug? What do you expect the community here to do? You can report bugs to the MathWorks: supportcases.mathworks.com/mwsupport/s/… — check for existing bug here first: mathworks.com/support/bugreports Commented Apr 5, 2024 at 13:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.