- #1

- 27

- 4

## Main Question or Discussion Point

Dear Forumers,

Given a simulink model:

http://www.femm.info/Archives/contrib/images/TransientLoudspeaker/SimulinkOverview.png

I would like to implement fast code for it.

I have no access to matlib or simulink at all, so I tried to implement the simulation in C code.

Code for the block 'EddySpeaker' is given, and the integrals are calculated by numerical approximation (trapezoid method, for example).

It seems that the approach I chose works (I compared it to the simulation of scilab xcos), but it's not stable when dt is not small enough.

Actually I'm afraid that these sort of problems are solved in a completely different way, like setting up ordinary differential equations

and make them solved by a solver like VCODE (that's what xcos do, as much as I get the picture).

My questions,

- practically, can this model be simulated by a numerical approach (like I described)?

I simply integrate acceleration, then velocity, then force and the results are fed back to the block 'EddySpeaker' which has its own code.

If yes, is it normal that I get unstability (like oscillation) when dt is not small enough?

- Can this model be described by ODEs and make them solved by a solver?

I'm asking this because the block 'EddySpeaker' has its own custom code. I read that codes can be translated into blocks though.

- what sort of C code is generated by the code generator in simulink? Is it a numerical type, or the ODE type (which is get solved by a solver)?

ps. I can paste my simplified code here, if needed.

Any help would be greatly appreciated,

Regards,

Akos

Given a simulink model:

http://www.femm.info/Archives/contrib/images/TransientLoudspeaker/SimulinkOverview.png

I would like to implement fast code for it.

I have no access to matlib or simulink at all, so I tried to implement the simulation in C code.

Code for the block 'EddySpeaker' is given, and the integrals are calculated by numerical approximation (trapezoid method, for example).

It seems that the approach I chose works (I compared it to the simulation of scilab xcos), but it's not stable when dt is not small enough.

Actually I'm afraid that these sort of problems are solved in a completely different way, like setting up ordinary differential equations

and make them solved by a solver like VCODE (that's what xcos do, as much as I get the picture).

My questions,

- practically, can this model be simulated by a numerical approach (like I described)?

I simply integrate acceleration, then velocity, then force and the results are fed back to the block 'EddySpeaker' which has its own code.

If yes, is it normal that I get unstability (like oscillation) when dt is not small enough?

- Can this model be described by ODEs and make them solved by a solver?

I'm asking this because the block 'EddySpeaker' has its own custom code. I read that codes can be translated into blocks though.

- what sort of C code is generated by the code generator in simulink? Is it a numerical type, or the ODE type (which is get solved by a solver)?

ps. I can paste my simplified code here, if needed.

Any help would be greatly appreciated,

Regards,

Akos