Opened 11 years ago

Closed 11 years ago

#2668 closed defect (fixed)

Sign error in matrix operations

Reported by: anonymous Owned by: Per Östlund
Priority: high Milestone: 1.9.1
Component: Frontend Version: trunk
Keywords: matrix operations Cc:

Description

Some matrix operations are not correctly done. For example in the following code:

model Matrix
  parameter Real u[3, 1] = [1; 1; 1];
  parameter Real v[3, 1] = [1; 0; 0];
  Real M[3, 3];
  Real A[3, 1];
  Real B[3, 1];
equation
  M = [1, 0, 0; 0, 1, 0; 0, 0, 1];
  A = u + v + M * (u - v);
  B = u + v - M * (v - u);
end Matrix;

A is not equal to B. In fact we get A=-B.

Moreover if we instantiate the model we get:
B[1,1] = M[1,1] * (v[1,1] - u[1,1]) + M[1,2] * (v[2,1] - u[2,1]) + M[1,3] * (v[3,1] - u[3,1]) - (u[1,1] + v[1,1]);
instead of:
B[1,1] = - M[1,1] * (v[1,1] - u[1,1]) + M[1,2] * (v[2,1] - u[2,1]) + M[1,3] * (v[3,1] - u[3,1]) + (u[1,1] + v[1,1]);

Change History (2)

comment:1 by Per Östlund, 11 years ago

Component: New InstantiationFrontend
Status: newaccepted

comment:2 by Per Östlund, 11 years ago

Resolution: fixed
Status: acceptedclosed

Fixed in r20224. We had a simplification rule for matrix +/- array that for some reason swapped lhs and rhs, which obviously doesn't work for subtraction.

Note: See TracTickets for help on using tickets.