Greetings.

I was declaring a function and his derivative like this:

class SandBox
    import Modelica.Blocks.Sources;

    Sources.Ramp    ramp(offset=-10, startTime=5, duration=20, height=20);

    function linear_der
        input   Real x;
        input   Real der_x;
        output  Real der_y;
    algorithm
        der_y := der_x;
    end linear_der;

    function linear
        annotation(derivative=linear_der);
        input   Real x;
        output  Real y;
    algorithm
        y := x;
    end linear;

    Real    y[4];

equation
    y[1] = ramp.y;
    y[2] = linear(y[1]);
    y[3] = der(y[1]);
    y[4] = der(y[2]);
end SandBox;

But when i run the simulation i get this:

>> simulate(SandBox, stopTime=30)
record
    resultFile = "Simulation failed.
The language feature differentiation of function SandBox.linear is not
supported. Suggested workaroung: no suggestion
Model is structurally singular, error found sorting equations y[2] =
SandBox.linear(y[1]);
y[1] = ramp.offset + (if time < ramp.startTime then 0.0 else if time <
ramp.startTime + ramp.duration then ((time - ramp.startTime) *
ramp.height) / ramp.duration else ramp.height);
 for variables y[1](4),
Model is structurally singular, error found sorting equations y[2] =
SandBox.linear(y[1]);
y[1] = ramp.offset + (if time < ramp.startTime then 0.0 else if time <
ramp.startTime + ramp.duration then ((time - ramp.startTime) *
ramp.height) / ramp.duration else ramp.height);
 for variables y[1](4),
Model is structurally singular, error found sorting equations y[2] =
SandBox.linear(y[1]);
y[1] = ramp.offset + (if time < ramp.startTime then 0.0 else if time <
ramp.startTime + ramp.duration then ((time - ramp.startTime) *
ramp.height) / ramp.duration else ramp.height);
 for variables y[1](4),
"
end record

>>


And if i replace this:

    y[4] = der(y[2]);

whit this:

    y[4] = linear_der(y[1],der(y[1]));

the simulation run without problems.

>> simulate(SandBox, stopTime=30)
record
    resultFile = "SandBox_res.plt"
end record

>>

Did i miss something on the declaration of the derivative of function f ?

Thanks.

-- 
Jorge Eduardo Cardona
[EMAIL PROTECTED]
jorgeecardona.blogspot.com
------------------------------------------------
Linux registered user  #391186
Registered machine    #291871
------------------------------------------------

Reply via email to