# Electrical – 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)

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.

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\$$ .