Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#5761 closed defect (worksforme)

Symbolic Jacobians not correct for Linearization and FMI

Reported by: Karim Adbdelhak Owned by: Lennart Ochel
Priority: high Milestone: 1.16.0
Component: FMI Version: v1.16.0-dev
Keywords: symbolic jacobian linearize Cc: Francesco Casella, Karim Adbdelhak, Andreas Heuermann

Description

The following simple model does produce "nan" entries for the jacobian entries:

loadString("
model M
  output Real lang = (u-1)^2;
  input Real u;
  Real x(start=1,fixed=true);
equation
  der(x) = x^2;
end M;
"); getErrorString();

linearize(M, simflags="-jacobian=coloredSymbolical"); getErrorString();

The start value of x seems to cause this, with zero there is no problem.

This is the generated linear system code:

model linear_M
  parameter Integer n = 1 "number of states";
  parameter Integer p = 1 "number of inputs";
  parameter Integer q = 1 "number of outputs";

  parameter Real x0[n] = {-nan};
  parameter Real u0[p] = {0};

  parameter Real A[n, n] = [nan];
  parameter Real B[n, p] = [-nan];
  parameter Real C[q, n] = [nan];
  parameter Real D[q, p] = [-1.999999932736385];

  Real x[n](start=x0);
  input Real u[p](start=u0);
  output Real y[q];

  Real 'x_x' = x[1];
  Real 'u_u' = u[1];
  Real 'y_lang' = y[1];
equation
  der(x) = A * x + B * u;
  y = C * x + D * u;
end linear_M;

Also setting the start value to 0.9 seems to be changed to 9 which is wierd.

Change History (3)

comment:1 by Andreas Heuermann, 5 years ago

There is a singularity at t=1, so what should be the correct linearization at t=1?

in reply to:  description comment:2 by Francesco Casella, 5 years ago

Resolution: worksforme
Status: newclosed

Replying to Karim.Abdelhak:

Indeed the analytical solution of the differential equation is x = x0/(1-t*x0), so if x starts from 1 it gets to infinity, from 0.9 it gets to 9.

What I find a bit strange is that matrix D is not exactly -2. Aren't we using an analytical analytical jacobian in this case? Is there some issue with single vs. double precision being used in different parts of the runtime code?

in reply to:  1 comment:3 by Vitalij Ruge, 5 years ago

Replying to AnHeuermann:

There is a singularity at t=1, so what should be the correct linearization at t=1?

B and C should be [0] (or are [0] in the sparse structure?). The mismatch in the number of the non-zeros elements between the routine and stucture is a good candidate for memory allocation problems.

Note: See TracTickets for help on using tickets.