EMERGENCY! A mistake or bug? Could you help me?

When I use a row vector times a column vector, a unexpected error happens: the reslut be rearranged automatically. For example, the code as
syms x1 x2 x3 real;
X=[x1;x2;x3];
syms u11 u12 u13 real;
U1=[u11;u12;u13];
(X-U1)'*(X-U1)
The answer produced by matlab is
(u11 - x1)^2 + (u12 - x2)^2 + (u13 - x3)^2
But all we know the result should be
(x1 - u11)^2 + (x2 - u12)^2 + (x3 - u13)^2
Why does matlab automatically change the result? What's wrong with the code? Is my mistake or a bug of matlab? Although the two result is equal in this situation, it will change the result of the following code.For example the following code is
syms e11 e12 e13 e21 e22 e23 e31 e32 e33 real
C1=[e11 e12 e13;e21 e22 e23; e31 e32 e33];
(X-U1)'*C1*(X-U1)
Help me, please! Waiting the answer online……

5 comentarios

Brisk
Brisk el 29 de Sept. de 2015

The used code is

if true
  syms x1 x2 x3 real;
  X=[x1;x2;x3];
  syms u11 u12 u13 real;
  U1=[u11;u12;u13];
  syms e11 e12 e13 e21 e22 e23 e31 e32 e33 real 
  C1=[e11 e12 e13;e21 e22 e23; e31 e32 e33];
  (X-U1)'*(X-U1)
end
James Tursa
James Tursa el 29 de Sept. de 2015
Why do you think the symbolic matrix multiply result will be wrong? What result do you get?
Walter Roberson
Walter Roberson el 29 de Sept. de 2015

http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency

My working policy is to close all "Urgent" or "Emergency" or "As soon as possible" postings as soon as I notice them. You didn't have the police wake me up to save someone's life, so it was not a real emergency. I was comatose with illness when you posted, but if it had been a real emergency I would have dragged myself out of bed.

However, the working policy is also not to close such posts if they have received a relevant Answer. You got lucky.

Jan
Jan el 29 de Sept. de 2015
Of course Walter's comment is not spam and should be considered carefully. Brisk, did you read it?
When I hit the "This is not spam" button, I get only an error message, but the mark does not disappear. Is this a known bug of the forum?
Walter Roberson
Walter Roberson el 29 de Sept. de 2015
Spam handling has been a bit fragile lately :(

Respuestas (1)

WAT
WAT el 29 de Sept. de 2015
Editada: Walter Roberson el 29 de Sept. de 2015
From your post:
The answer produced by matlab is
(u11 - x1)^2 + (u12 - x2)^2 + (u13 - x3)^2
But all we know the result should be
(x1 - u11)^2 + (x2 - u12)^2 + (x3 - u13)^2
Since (a-b)^2 = (b-a)^2 these expressions are equivalent.

La pregunta está cerrada.

Preguntada:

el 29 de Sept. de 2015

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by