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

Does it exst any way to use symbolic variables for paraametrzng a simulink model and getting a symbolic or semi symbolic solution?

Answers (2)

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

Thus, in conclusion no way to use symbolic "signals" exist?
In some measure this sound strange, since when coding, essentilally what simulink do is just computing a code-equivalent signal propagation without numerical evaluations
But Simulink is not computing the final answer explicitly from that code. That code uses numerical methods to solve the problem in a stepwise fashion.
Can you give the simplest example of what you'd like to do if Simulink supported symbolic computations.
Well, you're right, but I think numerical method do not necessarily exclude possibility to include some symbolic parameter.
Let me give a simple example:
I've a simple simulink linear model, whose behaviour is smooth on parameters, and solution or system response is expected to be smooth also on system parameters. Maybe don't know exactly parameters value for a realistic simulation, or just I don't want to set any becasue interested into a paramteric solution, where possible bviously. Ideally I'd set model parameters as symbolic variable with chosen names at my pleasure, and would expect to ses response as function of these parameters. I do not pretend it to work for arbitrary complexity model (alhough should be mostly?), but would be useful:
  1. Increase explainability of system behaviour
  2. perform a parametrc system analysis
  3. avoiding performing many simulations for exploring system behaviour against parameter space (the more parameters, the more simulations, unpleasant situation)
  4. found groups of parameters that interactin giving (or not giving!) response. I give a simple example.
Let's model a simple spring mass damper model, whose values of mass, elastic constant, damping are given as symbolic parameters (in case vectorial?) m,k,c
I already know ideal solution of free displacement, depending on abovementioned parameters, and I'd see f simulink would give me
  1. rght group of parameters
  2. dentification of criitical parameters
  3. depednance of solution on paramters
As beginning. I think would be a precious method of system analysis, reducing simulation efforts.
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.
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

Sign in to comment.

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.

Categories

Find more on General Applications in Help Center and File Exchange

Products

Release

R2023b

Asked:

on 5 Oct 2024

Edited:

on 6 Oct 2024

Community Treasure Hunt

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

Start Hunting!