1

In Modelica, I have a variable x which is dependent on (a, b,c). For a given simulation time, its plot (x,time) looks smooth and continuous. I would like to have the slope of this curve without having to explicitly differentiate der(x) because I get errors regarding the partial derivatives with respect to a, b or c. Is this possible? In other words I want the slope of the final output, without having to differentiate what it is behind it.

leoo321
  • 31
  • 4
  • Consider adding some line breaks and using the `code` formatting option of the editor to make this more readable. –  May 09 '14 at 09:53

2 Answers2

2

You cannot do something like this in Modelica itself because you do not have any access to the integrator, previous time, or similar. You can get an approximation in Modelica code by using sampling, but this slightly changes simulation results and may be a performance bottleneck:

model M Real signal = time; Real approx_der(start=0); discrete Real x(start=0); discrete Real t(start=0); equation when sample(0.1,0.1) then x = signal; t = time; approx_der = (x-pre(x)) / (t-pre(t)); end when; end M;

It is easier to simply use post-processing. Load up the result-file in octave, matlab or similar and plot the approximate derivative: plot(time(2:length(time)),diff(y) ./ diff(time))

sjoelund.se
  • 3,468
  • 12
  • 15
  • Thank you for your answer, actually I needed the value of the slope in real time. I used `Modelica.Blocks.Continuous.Derivative x_dot(start=1);`. I gave x as an input and got `x_dot.y` as the derivative with no problems. – leoo321 May 11 '14 at 14:47
2

Modelica.Blocks.Continuous.Derivative x_dot(start=1) This provides an approximation of the derivative. I gave the x as an input and got x_dot.y as the derivative with no problems.

leoo321
  • 31
  • 4