x = 2

y = a + b;

z = x + y

This line is going to be text.

Part 3

Now let's clear x, y, and z

Clear[x, y, z]

Part 4

Enter in the constants of the spring /mass/damper system.

k = 2;

c = 1/2;

m = 1;

Part 5

Now define the A, B, C, and D matrices

Amat=(({{0, 1}, {-k/m, -c/m}}));

Bmat=(({{0}, {1/m}}));

Cmat=(({{1, 0}}));

Dmat = (0);

Part 6

Calculate the eigenvalues and eigenvectors of the A matrix

EigenvaluesA = Eigenvalues[Amat] // Simplify

EigenvectorsA = Eigenvectors[Amat] // Simplify

Seperate these into two individual eigenvalues and eigenvectors.

λ1 = EigenvaluesA[[1]] // Simplify

λ2 = EigenvaluesA[[2]] // Simplify

Be careful, Mathematica 5.0 gives eigenvectors in row form.

v1=(({{EigenvectorsA[[1, 1]]}, {EigenvectorsA[[1, 2]]}}))

v2=(({{EigenvectorsA[[2, 1]]}, {EigenvectorsA[[2, 2]]}}))

Part 7

We can now check to make sure that these satisfy the definition of an eigenvalue and eigenvector.  Use the Simplify function to simplify the expression.

(Amat - λ1 IdentityMatrix[2]) . v1 // Simplify

(Amat - λ2 IdentityMatrix[2]) . v2 // Simplify

Part 8

Now let's calculate the characterstic equation of this system.  This is a function of λ

p[λ_] = Det[λ*IdentityMatrix[2] - Amat]

Part 9

Verify that the eigenvalues we obtained previously are roots of the characteristic equation.

p[λ1] // Simplify

p[λ2] // Simplify

Part 10

We can calculate the transfer function between the input and output of this system.

temp = 
      Cmat . Inverse[s IdentityMatrix[2] - Amat] . Bmat + Dmat

Notice that this returns a matrix, if we want to extract the transfer function from the matrix, we pull out the 1,1 element of the matrix.

G[s_] = temp[[1, 1]]

Part 11

We can now calculate the response of the system to a step input in the Laplace domain.

Y[s_] = G[s]*1/s // Simplify

Inverse Laplace transform this to obtain the response of the system in the time domain.

y[t_] = InverseLaplaceTransform[Y[s], s, t] // FullSimplify

Part 12

Now let's plot the response of the system

Plot[y[t], {t, 0, 10}]

Let's compare to see how this compares to the results that we obtained with Simulink.