I have the following transfer function that I am trying to model in MATLAB with some additional unity white noise:

$$G(s)=\frac{1}{s^3 + \beta s^2}$$

I used the following to obtain the continuous state space equation:

beta = 0.2;
b = [0 0 0 1];
a = [1 beta 0 0];
[A,B,C,D] = tf2ss(b,a);

My understanding is that the tf2ss() function provides me with the values A and B which can be used in the following equation:

dxdt = Ax + Bu, where x is the initial condition and u is the unity white noise.

Upon running the above code snippet, I obtain the following values for A and B:

A = [-0.2,0,0; 1,0,0; 0,1,0]
B = [1; 0; 0]

Here is where I am running into trouble (although I may have run into an issue before with my assumptions regarding tf2ss()). I do not understand how to write the differential equation function required to use ode45(). I have tried the following:

function dx = mydiffeq(t,x)
    A = [-0.2,0,0;1,0,0;0,1,0];
    B = [1;0;0];

    dx = A*x + B*randn(1);


And then I call it as follows:

tspan = [0 10];
xnot = 100;

[t,y] = ode45(@mydiffeq, tspan, xnot);

Obviously, I have a problem due to the size of my A and B matrices. I know that I am doing this wrong, but I do not know how to fix it.


You're doing pretty much everything right. The only problem is that your system is a third order system (s^3) and hence, the state x in

dx = A*x + B*u

is 3x1 but your initial condition xnot is a scalar. Replace

xnot = 100


xnot = [0 0 0].';

(or whatever initial condition you have) and it should work.

  • $\begingroup$ Thank you. Such a simple thing to miss... but I didn't even think to look there. $\endgroup$ – embedded_guy Nov 17 '15 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.