问题
I would like to perform integration of a function of a variable other than time in Modelica, but I don't know how to do it. For example, how can I evaluate the integral of x dx with upper limit 5 and lower limit 2?
∫x dx=x^2/2
回答1:
Modelica was not designed to be a CAS (computer algebra system) as Maple, Mathematica or Matlab, but with a little coding you can do it anyway. The thing is that your problem can not be solved automatically symbolically with Modelica tools, but numerically yes.
In order to solve it numerically you have to do the trick to substitute the x with the time variable since in Modelica you can perform derivatives and therefore integrals only with respect to time. Therefore you can create a signal source with the function you want to integrate and then use it as input of the Modelica.Blocks.Continuous.Integrator
block, that implements this simple equation:
model Integrator
input Real u;
output Real y;
equation
der(y) = u;
end Integrator;
Finally if you send as input to this block zero for t<2
and t<5
, then you should get in output the correct value of your integral between 2
and 5
:
I hope this helps, Marco
来源:https://stackoverflow.com/questions/16457839/integration-of-function-in-modelica