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.

Reply to
crazygrey
Loading thread data ...

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.

Reply to
Tim Wescott

''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

Reply to
crazygrey

Dnia 15-05-2007 o 16:49:27 crazygrey napisa³(a):

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]

Otherwise I would read about convolution with impulse response.

Reply to
Mikolaj

Here are my matlab test files

inertia.m %file must have the same name as function name

-------------------------- function dy=3Dinertia(t,y)

%excitation u=3D0; % well, line useful if you remove that one belowe u=3D(sign(sin(t))>0); % if removed then no excitation is applied

%diff equation dy/dt + y =3D u -> s*y + y =3D u % y(s+1)=3D u - > y/u =3D 1/(1+s) dy=3Du-y;

-------------------------- main.m

% model 1/(s+1) % ODE with excitation

[t,y]=3Dode45(@inertia,[0 10],[0.1]); plot(t,y(:,1)); hold on; plot(t,(sign(sin(t))>0),'r'); %this is my scary excitation, paste anythi= ng

% comments , you see 2 files, run the main.m. one, [0 10] is how long, 0= .1 =

is initial cond. % have fun

Reply to
Mikolaj

Thanks that helped

Reply to
crazygrey

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.