# Simulating a non-linear system in Simulink

I have a set of non-linear equations, which I would like to model in Simulink in order to compare to their linear counterpart.

Here is the block diagram of my setup. The state-space block represents the linear model, while the Matlab function contains the non-linear equations. Linearised Response: Non Linear Response: I am trying to simulate the following non linear equations: The function $$\\dot{\vec x} = f(\vec x, u)\$$ is outputting derivative of $$\\vec x\$$, not $$\\vec x\$$ itself. The function block that finds $$\\dot{\vec x}\$$ from $$\\vec x\$$ and $$\u\$$, then feeds it to an integrator and feeds the $$\\vec x\$$ back to the block, and extracts $$\y\$$ from it.

with these parameters:

g = 9.81;
m = 0.05;
R = 1;
L = 0.01;
C = 0.0001;
x1 = 0.012; %initial condition 1: displacement
x2 = 0;     %initial condition 2: velocity
x3 = 0.84;  %initial condition 3: acceleration


This is how I coding the Matlab function to represent my non-linear system:

    function [xdot,y] = fcn(x,u)

% define your constants
g = 9.81;
m = 0.05;
R = 1;
L = 0.01;
C = 0.0001;
%   x1 = 0.012; %initial condition 1: displacement
%   x2 = 0;     %initial condition 2: velocity
%   x3 = 0.84;  %initial condition 3: acceleration

% nonlinear set of equations
xdot = [x(2); g-((C/m)*(x(3)/x(1))^2); -((R/L) +(((2*C)/L)*(((x(2)*x(3))/((x(1))^2)))))] + [0;0;1/L]*u;

y = x';


My question is: Where do the initial conditions come into play with the non-linear mode? To calculate Matrix A in the state space block for the linear systems the initial conditions are used.

How should they be included in the non linear model coded above? Since as they are defined, they will never be utilized within the code.

• Last time I used SIMULINK was quite long ago during my studies. To solve a differential equations we used integrator instead of derivative, so far I can remeber... – Crowley Nov 28 '18 at 20:04
• Thanks for you input. Which part are you referring to? Indeed it is an integrator block I am using in the Simulink model defined by 1/s – rrz0 Nov 28 '18 at 20:05
• Note that your linearized system is not stable. The 10^11 exponent in the graph should have clued you in. Have you verified its eigenvalues? – Edgar Brown Nov 28 '18 at 20:21
• @EdgarBrown this is an open loop system so I was expecting an unstable response. – rrz0 Nov 28 '18 at 20:39
• @EdgarBrown the linearized matrix A was taken from pdfs.semanticscholar.org/d25a/…, and the eigenvalues do not seem to be correct for the given matrix. I am trying to reproduce the results in the paper. – rrz0 Nov 28 '18 at 20:47

## 1 Answer

If you want to use initial conditions for the $$\ X_i \$$ variables in the non-linear model, just assign them to the external integrator (1/s) block, or add them as a constant vector after the integrator.

As it is, I am not sure how the simulation is working at all as the non-linear system is not defined for $$\ X_1 = 0\$$ .