# Find the system response given the initial condition

I am given these sets of equations for a gantry crane:

1) $$M\frac{d^2x}{dt^2}+D\frac{dx}{dt}-mg\theta =u$$

2) $$ml\frac{d^2\theta }{dt^2}+mg\theta +m\frac{d^2x\:}{dt^2}=0$$

3) $$y=x+l\theta$$

Where $$x$$ is the position of the trolley; $$M$$ is the mass of the trolley; $$m$$ is the mass of the payload; $$\theta$$ is the angular position of the payload; $$D$$ is the damping coefficient; $$y$$ is the payload position; $$u$$ is the force applied to the trolley; $$l$$ is the cable length.

Based on the equations above, I have found the transfer function of this system to be $$G\left(s\right)=\frac{y\left(s\right)}{u\left(s\right)}=\frac{s^2\left(l-1\right)+g}{Mls^4+Dls^3+\left(M+m\right)gs^2+Dgs}$$

Now, I have to find the system response if $$u$$ is zero and the payload is shifted by an angle of $$10^{\circ }$$.

What this means is that we must now consider the initial condition of a $$10^{\circ }$$ angle when we do the Laplace transform; however I can't figure out how to incorporate the initial condition in my equations.

Also, if $$u$$ is zero, how is it mathematically possible to find $$y(s)$$ to be not zero, given that $$y(s)=u(s)G(s)$$?

When deriving the transfer function it is usually implicitly assumed that the initial conditions are zero. However the Laplace transform of the derivative of a variable with respect to time with initial conditions is defined by

$$\mathcal{L}\left\{\frac{d^n y}{dt^n}\right\}(s) = s\,\mathcal{L}\left\{\frac{d^{n-1} y}{dt^{n-1}}\right\}(s) - \left.\frac{d^{n-1} y}{dt^{n-1}}\right|_{t=0^+}.$$

So for example $$\mathcal{L}\{\tfrac{d}{dt}y\}(s)=s\,\mathcal{L}\{y\}(s)-y(0^+)$$ and $$\mathcal{L}\{\tfrac{d^2}{dt^2}y\}(s) = s\,\mathcal{L}\{\tfrac{d}{dt}y\}(s) - \tfrac{d}{dt}y(0^+) = s^2\,\mathcal{L}\{y\}(s) - s\,y(0^+) - \tfrac{d}{dt}y(0^+)$$.

The unforced system response of the system with initial conditions can be calculated by taking the inverse Laplace transform of the resulting expression. However it might be easier to not switch to and from the frequency domain and just solve it directly in the time domain.

• Thank you for your answer fibonatic. In the second equation I have posted above, its Laplace Transform would be: $ml\left[s^2\theta \left(s\right)-s\theta \left(0^+\right)-\frac{d}{dt}\theta \left(0^+\right)\right]+mg\theta \left(s\right)+ms^2X\left(s\right)=0$. However, I don't know what to do to solve $\frac{d}{dt}\theta \left(0^+\right)$. Whose derivative am I going to find and then replace it with the initial condition? – snitchben Mar 6 '19 at 17:20
• @snitchben I think you would have to assume that $\frac{d}{dt}\theta \left(0^+\right)=0$, similar to the initial conditions for $x$. – fibonatic Mar 6 '19 at 17:26
• So, you're saying that I would have to consider $X\left(0^+\right)=0$, right? – snitchben Mar 6 '19 at 17:28
• @snitchben Yes. I think one can always make the assumption that all initial conditions are zero unless otherwise specified. In your case only $\theta(0)$ is given, so the otger initial conditions can still be assumed to be zero. If you want to see the effect of the other initial conditions you can of course always change the other initial conditions as well. And since you want an analytical expression you can also just use variables for each initial condition. – fibonatic Mar 6 '19 at 17:38
• From the first equation that I have posted, if $u=0$ I get this equation: $\theta \left(s\right)=X\left(s\right)\left[\frac{Ms^2+Ds}{mg}\right]$. From the second equation, I get: $X\left(s\right)=-\frac{\theta \left(s\right)\left[mg-ls^2\right]-ls\theta \left(0^+\right)}{s^2}$. The problem here is that I can't find a solution about $\theta(s)$ and $X(s)$, because they get simplified if I replace one or the other in one of these equations. – snitchben Mar 6 '19 at 18:11

Laplace transform works in the frequency domain, whereas initial conditions are for transient simulations in the time domain, so it does not make sense to apply an initial condition to a Laplace transform.

What does make sense is to do a time-domain simulation with the initial condition you mention. The fact that $$u$$ is equal to zero simply means that there are no external horizontal forces applied on the trolley. However, with an initial condition of 10° for $$\theta$$, the angular acceleration of mass will result in a non-zero $$\theta$$ as a function of time, which in turn will result in a non-zero $$x$$ as a function of time (c/f your first and second equations).

There are various tools out there for time-domain simulations, you may not need to use the Laplace transform at all for this, it's simply solving coupled differential equations. Here is an example with GNU Octave. I am using a state-space representation rather than a Laplace transform because it allows me better control of the states, which makes it easier to specify the initial conditions.

I define my state vector as:

$$X = \begin{bmatrix} x \\ \dot{x} \\ \theta \\ \dot{\theta} \end{bmatrix}$$

which gives:

$$\dot{X} = \begin{bmatrix} \dot{x} \\ \ddot{x} \\ \dot{\theta} \\ \ddot{\theta} \end{bmatrix}$$

The input is $$u$$ and output is $$y$$. The state-space representation is written as:

$$\dot{X} = AX + Bu \\ y = CX + Du$$

where $$A$$ is a 4x4 matrix, $$B$$ a 4x1 matrix, $$C$$ a 1x4 matrix and $$D$$ a 1x1 matrix, i.e. a scalar.

After re-arranging the differential equations to have $$\dot{X}$$ as a function of $$X$$ and $$u$$ only, I get the following matrices:

$$A = \begin{bmatrix} 0 & 1 & 0 & 0 \\ 0 & -D/M & mg/M & 0 \\ 0 & 0 & 0 & 1 \\ 0 & D/(Ml) & -(g/l)*(1+m/M) & 0 \end{bmatrix} \\ B = \begin{bmatrix} 0 \\ 1/M \\ 0 \\ -1/(Ml) \end{bmatrix} \\ C = \begin{bmatrix} 1 & 0 & l & 0 \end{bmatrix} \\ D = 0$$

In Octave, with some randomly chosen values, the code looks something like this

% Parameters
M=1;
m=0.15;
D=0.5;
g=9.81;
l=1;
theta_0=10*pi/180;

% State-space matrices
A = [0 1 0 0; 0 -D/M m*g/M 0; 0 0 0 1; 0 D/(M*l) -(g/l)*(1+m/M) 0];
B = [0 1/M 0 -1/(M*l)]';
C = [1 0 l 0];
DD = 0; % using DD to avoid confusion with parameter D
G = ss(A,B,C,DD);

% Time-domain simulation
t = linspace(0,10,500); % time vector
u = zeros(size(t));     % input vector u
x0 = [0 0 theta_0 0];   % initial conditions
lsim(G,u,t,x0)


Which gives the following result:

The other method is to solve the differential directly with an ode solver, which yields the same results.

First you need to define a function to implement your differential equations:

function dx = gantry_crane(t,x)

M = 1;
m = 0.15;
D = 0.5;
l = 1;
g = 9.81;

dx(1) = x(2); % dx/dt
dx(2) = (m*g*x(3) - D*dx(1))/M; %d^2x/dt^2
dx(3) = x(4); % dtheta/dt
dx(4) = -(m*g*x(3)+m*dx(2))/(m*l); %d^2theta/dt^2

end


This is saved under the file name gantry_crane.m. You then call the ode solver as follows:

theta_0=10*pi/180;
x0 = [0 0 theta_0 0]
[t,x] = ode45(@gantry_crane,[0 10],x0);
y = x(:,1) + x(:,3); % y = x + l*theta and l=1
plot(t,y)


which gives the following result:

• How can I do this simulation by using initial in MATLAB? I can't figure out the space state equations to use initial. – snitchben Mar 7 '19 at 6:41
• The code I have given you should also work in MATLAB. You could also solve the differential equations directly using the ode solver. – am304 Mar 7 '19 at 10:08
• There may be a sign mistake in my matrix calculations. Have you double-checked them? I did it quite quickly, so it's not impossible... – am304 Mar 7 '19 at 16:11
• I actually did not find any mistake. Can you please check the signs again? I believe A must have the second term of the last row positive. – snitchben Mar 7 '19 at 16:31
• See my updated answer with solving the differential equations directly - I haven't got time to go through the matrix calculations again I'm afraid. – am304 Mar 7 '19 at 16:34