Opened 11 years ago

Closed 11 years ago

#2606 closed defect (invalid)

Bad equation solving (wrong symbolic manipulation)

Reported by: Adrian Pop Owned by: probably noone
Priority: blocker Milestone: 1.9.1
Component: Backend Version: trunk
Keywords: Cc: Lennart Ochel, Willi Braun, Martin Sjölund

Description

Solving this system of equations:

a = (1 - b)*c + b * d;
a = y;
c = gy;
d = ly;

for b should result in:

b = (gy - y)/(gy + ly)

but OpenModelica does:

b = (gy - y)/(gy - ly)

This happens in the AVM model:
C2M2L_CyPhy.Test_Assemblies_Decl.SystemDesignTest
The system is:

driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.proportional_Combining.y = 
 (1.0 - driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.proportional_Combining.lim_p) * 
 driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.proportional_Combining.u2 + 
 driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.proportional_Combining.lim_p * 
 driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.proportional_Combining.u1;

driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.positive_Negative_Split.u = 
driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.proportional_Combining.y;

driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.gain.y = 
driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.proportional_Combining.u2;

driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.limited_Map.y = 
driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.proportional_Combining.u1;

solved for:
driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.proportional_Combining.lim_p
results in this code for initialization:

/*
 equation index: 7718
 type: SIMPLE_ASSIGN
 driveLineDesign._example_Engine_Basic_Tstat_Degas._torque_and_fueling_1_1._proportional_Combining._lim_p = 
 DIVISION(
 driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.gain.y - 
 driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.positive_Negative_Split.u, 
 driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.gain.y - 
 driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.limited_Map.y)
 */

which is clearly wrong, it should be addition instead of subtraction in the divisor:

driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.gain.y + 
 driveLineDesign.example_Engine_Basic_Tstat_Degas.torque_and_fueling_1_1.limited_Map.y

Change History (7)

comment:1 by Adrian Pop, 11 years ago

Cc: Martin Sjölund added

Question: can we look with the debugger at the solving process to see where the wrong symbolic manipulation happens?

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

model M
  Real y = 2*time,gy = 2*time,ly = 2*time;
  Real a,b,c,d;
equation
  a = (1 - b)*c + b * d;
  a = y;
  c = gy;
  d = ly;
end M;

Gives

  <equation index="4">
    <assign>
      <defines name="b" />
      <depends name="d" />
      <depends name="a" />
      <depends name="c" />
      <rhs>DIVISION(c - a, c - d)</rhs>
    </assign>
    <operations>
      <solve>
        <old>
          <lhs>a</lhs>
          <rhs>(1.0 - b) * c + b * d</rhs>
        </old>
        <new>
          <lhs>b</lhs>
          <rhs>(c - a) / (c - d)</rhs>
        </new>
        <assertions>
        </assertions>
      </solve>
      <flattening>
        <original>a = (1 - b) * c + b * d;</original>
        <flattened>a = (1.0 - b) * c + b * d;</flattened>
      </flattening>
    </operations>
  </equation>

comment:3 by Adrian Pop, 11 years ago

Seems that:

dere = Differentiate.differentiateExpSolve(e, cr);
//where e is: a - ((1 - b)*c + b * d) and cr is b
//results in (c - d) instead of (c + d)

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

Well... Isn't it actually correct?

a = (1-b)*c+b*d
a = c-bc+bd
0 = c-bc-a+bd
b(c-d) = c-a
b = (c-a) / (c-d)

comment:5 by Adrian Pop, 11 years ago

I would say no:

a = (1 - b)c + bd 
a = c - bc + bd // multiply c with (1 - b)
a - c = - b(c + d) // move c on the other side and factor b
c - a = b ( c + d) // move -1 on the other side
b = (c - a) / (c + d) // divide
Last edited 11 years ago by Adrian Pop (previous) (diff)

in reply to:  5 comment:6 by Martin Sjölund, 11 years ago

Replying to adrpo:

a = c - bc + bd multiply c with (1 - b)
a - c = - b(c + d)
move c on the other side and factor b

Wrong sign inside the parenthesis.

comment:7 by Adrian Pop, 11 years ago

Resolution: invalid
Status: newclosed

damn, is this damn cold :)

Note: See TracTickets for help on using tickets.