# Is there any way to perform an at least partially symbolic smulation (using ODE or discrete model) in simulink?

21 views (last 30 days)

Show older comments

##### 0 Comments

### Answers (2)

Walter Roberson
on 5 Oct 2024 at 19:25

If you turn rapid acceleration off, and use coder.extrinsic then you can include symbolic calculations within any one MATLAB Function Block. However, you cannot pass symbolic results as signals between blocks, and you need to convert any results back from symbolic to double before emitting them from the block.

I suspect also that you cannot declare symbolic values as global or persistent

##### 7 Comments

Walter Roberson
on 6 Oct 2024 at 20:09

Simulink is designed to produce numeric solutions, not parametric solutions.

At any one time, Simulink signals are numeric and have specific values.

There are ways in Simulink to create constructs that adapt to changes in input signals, so it is often possible to "tune" models -- but still at any time all signals have specific numeric value. Simulink is not doing any kind of symbolic manipulation or analysis to tune models; it is strictly varying numeric parameters.

Paul
on 6 Oct 2024 at 21:22

Edited: Paul
on 6 Oct 2024 at 21:25

Let's suppose Simulink could do what you want, at least my interpretation of what I think you're asking for.

Here's the second order model with all parameters and initial conditions symbolic, and simulating it as Simulink would for the simplest possible integration scheme.

syms M K C x0 xdot0 x real

% M xddot + c*xdot + K*x = 0;

%x1 = x;

%x2 = xdot;

%X1dot = x2;

%x2dot = (-C*x2 - K*x1)/M;

t = 0;

dt = 0.1;

x = [x0;xdot0];

for ii = 1:10

xdot = [x(2); -(C*x(2) - K*x(1))/M];

x = x + dt*xdot;

t = t + dt;

end

x = simplify(x)

That results doesn't look very useful. Imagine how complex it would look using a more complicated integration, or if the model itself was even marginally more complicated. Nevermind all of the the other stuff that Simulink has to deal with, like inequalities, event detection, etc. Basically, Simulink is not the tool you're looking for.

I agree with your point, but Simulink signals don't have to be numeric. Simulink supports string and boolean and enumerated types, though it's quite possible that the latter two are implemented under the hood with numerics.

edit: I guess Answers is still suffering from not rendering symbolic output. I wonder what happened and why it's taking so long to fix. @Tushal Desai

John D'Errico
on 6 Oct 2024 at 19:21

Edited: John D'Errico
on 6 Oct 2024 at 19:52

Essentially, no. This is a frequent question about tools like ODE45 too. Simulink is a purely numerical tool, like ODE45 and other numerical solvers. You cannot parameterize a problem in terms of symbolic unknown parameters.

Can you perform symbolic computations inside a function that Simulink may employ? Well, yes. But I think that is not the gist of your question. Simulink does not return a solution in a functional form. It is a simulation tool.

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!