# Simulation of a nonlinear system in MATLAB

I have a nonlinear model that is represented by: TVo/V*X''+X'=KVo/V*D where D is the control input. I wanted to design an integral
controller to control X to some Xd(desired) Assuming that V=Vo. I did that with no problem. Next, I wanted to design a gain scheduling to compensate for slowly varying V. I did that as well.
Now I have to simulate the system performance with MATLAB using both controllers to a square wave input in which Xd varies between X1 and X2 while slowing varying V. I'm not sure about the square input part, I don't quite understand what and how to do it. I might be missing something here.
If it helps I will explain how I found the design for the integral controller: Integral control: I did change of variables so that Y1=X, Y2=Y1'=X' Y1'= Y2, Y2'=KD/T-Y2/T X-Xr=e=W' (error which at steady state becomes zero b/c of the integral controller). D=-K1Y1-K2Y2-K3W (Assuming linear PI controller). After linearing the system, I ended up with 2 state spaces that represent Y1-Y1ss, Y2-Y2ss & W-Wss (where ss represents steady state).
[ Y1-Y1ss;Y2-Y2ss;W-Wss]' = [0 1 0;-K*K1/T (-1-K*K2)/T -K*K3/T;1 0 0]* [Y1-Y1ss;Y2-Y2ss;W-Wss]
All of K,K1,K2,K3 & T have to be chosen so that the matrix is hurwitz.
Any explanation or help would be appreciated. Thanks.
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
crazygrey wrote:

type 'help square'?
I know there's a square wave source in simulink. If you're not doing this in simulink then just make a source that looks at the value of t mod period to see where to switch. Your system is otherwise smooth, so you may want to run the solver right up to the switching point on your square wave supply, then switch the input and run it up to the next switching point -- this will save you and your solver a lot of time and grief.
--

Tim Wescott
Wescott Design Services
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>

''square'' generates basically a square wave with some period and duty cycle. If I used an (ode45) solver, how do I incorporate that with the square input? Can you elaborate on the switching point note you mentioned?
Sorry to bother you. Thanks
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>

Hmm, differential equation's solution has 2 parts. One dependent on initial conditions (ode45 solution) and one dependent on excitation.
I'm not sure if I'm right but...
Matlab ode45 uses @fun which you must build. It contains your equation. I would include excitation inside of @fun because solving ODE is iterative procedure (Runge-Kutta and so on). To find if it is good idea I'would try square excitation on 1/(1+s) equation with zero initial conditions.
[y/u =1/(1+s) in Laplace operator form is dy/dt + y = u where u is square wave]
--
Mikolaj

<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Here are my matlab test files
inertia.m    %file must have the same name as function name -------------------------- function dy=inertia(t,y)
%excitation u=0;      % well, line useful if you remove that one belowe u=(sign(sin(t))>0); % if removed then no excitation is applied
%diff equation dy/dt + y = u -> s*y + y = u % y(s+1)= u - > y/u = 1/(1+s) dy=u-y;
-------------------------- main.m
% model 1/(s+1) % ODE with excitation
[t,y]=ode45(@inertia,[0 10],[0.1]); plot(t,y(:,1)); hold on; plot(t,(sign(sin(t))>0),'r');    %this is my scary excitation, paste anything
% comments , you see 2 files, run the main.m. one, [0 10] is how long, 0.1 is initial cond. % have fun
--

Mikolaj

<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
On May 15, 5:40 pm, Mikolaj

Thanks that helped