# Non-linear simulink function block help.

11 views (last 30 days)
Mark Dawson on 13 Sep 2019
Answered: Priyanshu Mishra on 16 Sep 2019
So I have my actual matlab file working perfectly, however, I need to transfer this to a simulink file that takes input x(t) and returns output phi(t). Just in standard input, process, output format. Only problem is I've never used simulink, and ive got no Idea where to start with this. The code I used is shown bellow:
%System Constants
L1 = 20;
L1A = 10;
L1B = 10;
L2 = 50;
H= 0.47;
%System Initial Physical Parameters
lambda1p = 2;
lambda2p = 2;
lambda3p = 1/(lambda1p*lambda2p);
%System Physical Constants
M = 17.5; %Mass of the mass (g)
c = 0.696; %Damping Co-efficient
mu = 562.01; %Small Strain shear modulus (kPa)
epsilon = 2.39e-11; %Di-electric Permitivity (F/m)
roe = 1522;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Mathematical Data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Input Waveform Charecteristics
A = 0.011; %Desired Peak Amplitude (mm)
T = 20; %Waveform Period (S)
f = 1/T; %Frequency (Hz) of Waveform
%Symbolic Equations
syms t
%x = @(t)A*sin(2*pi*f*t); %Sinusoidal Input Trajectory
%x = @(t)(2*A/pi)*asin((sin(2*pi*f*t))); %Triangular Input Trajectory
x = @(t)((((heaviside(t-1)+heaviside(9-t))/2)+((heaviside(t-3)+heaviside(6-t))/2))-1)*A; %Stair Input Trajectory
lambda1A = @(t)((L1A*lambda1p)+x(t))/L1A; %Stretch Factor 1A eqn
lambda1B = @(t)((2*lambda2p)-lambda1A(t)); %Stretch Factor 1B eqn
lambda1Adot=symfun(diff(lambda1A(t)),t); %1st Differential of Stretch Factor 1A (array)
lambda1Bdot=symfun(diff(lambda1B(t)),t); %1st Differential of Stretch Factor 1B (array)
lambda1Bdot_t=@(t) eval(lambda1Bdot); %1st Differential of Stretch Factor 1B (function)
lambda1A2dot=symfun(diff(diff(lambda1Adot(t)),t),t); %2nd Differential of Stretch Factor 1A (array)
lambda1A2dot_t=@(t) eval(lambda1A2dot); %2nd Differential of Stretch Factor 1A (function)
lambda1B2dot=symfun(diff(diff(lambda1Bdot(t)),t),t); %2nd Differential of Stretch Factor 1B (array)
lambda1B2dot_t=@(t) eval(lambda1B2dot); %2nd Differential of Stretch Factor 1B (function)
%Timebase
t = [0.01:0.1:9.99];
%Numerical Arrays
x = x(t); %Store Numerical results of function for given t
lambda1A = lambda1A(t); %Store Numerical results of function for given t
lambda1B = lambda1B(t); %Store Numerical results of function for given t
lambda1Bdot_t=lambda1Bdot_t(t); %Store Numerical results of function for given t
lambda1A2dot_t=lambda1A2dot_t(t); %Store Numerical results of function for given t
lambda1B2dot_t=lambda1B2dot_t(t); %Store Numerical results of function for given t
%%%%%%%%%%%%%%%%%%%%%%%%%%%Charecteristic Equation%%%%%%%%%%%%%%%%%%%%%%%%%

Priyanshu Mishra on 16 Sep 2019
To convert the MATLAB file into Simulink model, you can use MATLAB function block. Follow this sequence in Simulink -
In library browser – Simulink>>user defined functions >> MATLAB function