Opened 11 years ago

Closed 10 years ago

#2707 closed defect (fixed)

Unparsing of expression n*(n*v) produces wrong result for vectors

Reported by: carlj@… Owned by: Per Östlund
Priority: blocker Milestone: 1.9.1
Component: Frontend Version: trunk
Keywords: Cc:

Description

Unparsing destroys the following model by removing parentheses:

model TimesParentheses
  parameter Real[3] n = {0, 1, 0} "Normalized vector";
  parameter Real[3] v = {1, 2, 3} "Vector to project on n"
  Real[3] x "Projection of v on n";
equation
  x = n * (n * v);
end TimesParentheses;

After unparsing, the equation has changed to

  x = n * n * v;

which evaluates as

 x = (n * n) * v;

which is a totally incorrect way of computing a projection.

Change History (5)

comment:1 by Martin Sjölund, 11 years ago

Owner: changed from somebody to Per Östlund
Status: newassigned

comment:2 by Per Östlund, 11 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r20866.

comment:3 by carlj@…, 11 years ago

Resolution: fixed
Status: closedreopened

Thank you for the fast fix!

However, here is a modified model that is unparsed incorrectly:

model TimesParentheses
  parameter Real[3] a = {1,1,1};
  parameter Real[3] b = {1,0,1};
  parameter Real[3] n = {0, 1, 0};
  parameter Real[3] v = {1, 2, 3};
  Real[3] x;
equation
  x = n * ((n * v)/(a*b));
end TimesParentheses;

which now is unparsed as:

model TimesParentheses
  parameter Real[3] a = {1, 1, 1};
  parameter Real[3] b = {1, 0, 1};
  parameter Real[3] n = {0, 1, 0};
  parameter Real[3] v = {1, 2, 3};
  Real[3] x;
equation
  x = n * n * v / (a * b);
end TimesParentheses;

leading to the same problem as before.

comment:4 by Per Östlund, 10 years ago

Ok, I've made another fix in r20918. The expression in the model above is now unparsed as n * (n * v / (a * b)), which seems correct to me.

Edit: Corrected parentheses.

Last edited 10 years ago by Per Östlund (previous) (diff)

comment:5 by carlj@…, 10 years ago

Resolution: fixed
Status: reopenedclosed

Thanks perost, this seems to work like a charm!

Note: See TracTickets for help on using tickets.