I fixed your notebook (attached). First, the % refers to the output of the last evaluation. I would avoid it at most costs -- it is useful for interactive use of Mathematica but the preferred approach is to assign a variable to something. % works well until you use it out of order one time and you have a bug that is hard to find. Replace
StateResponse[ssM, UnitStep[t], t]
Plot[Evaluate[%], {t, 0, 10}, PlotRange -> All]
with
ans = StateResponse[ssM, UnitStep[t], t]
Plot[Evaluate[ans], {t, 0, 10}, PlotRange -> All]
Next,you are misusing Module[]. Module is meant for procedures to make variable local to the procedure. There are two mistakes here, First you are using module at the input prompt. For what you are doing, creating a statespace model and plotting its response, I would either do it all at the input prompt without the module, or make a procedure that has your module and return some result (i.e. the statespace model, the response, or even the plot, or a list of all of the above). The second issue is that you accidentally created a list instead of a series of operations:
In the attached notebook, I kept your Module structure but you had commas in the wrong place -- you were constructing a list of actions when what you really want is a sequence of steps -- I removed the {} and put semicolons after each line. A Module should look like this:
Module[{localvar1, localvar2},step1; step2; step3;...]
You had
Module[{localvar1, localvar2},{step1, step2, step3, ...}]
which for many reasons can have some strange results (like you were observing). After the initial example, I showed what I think is what you were looking for -- construct the matrices with symbols, then pass the symbolic matrices to a procedure that substitutes the numbers and generates the responses (returning a list of the statespace model and its plotted response). Note you could return anything you wanted in the list such as the raw data (ans), the numerical matrices, etc.
The procedure looks like this: first define a,b,c,d in terms of m1,m2,k then:
stateSpacePlotter[aMatrix_, bMatrix_, cMatrix_, dMatrix_, m1val_,
m2val_, kval_] := Module[{ans, ssM},
ssM = StateSpaceModel[{aMatrix, bMatrix, cMatrix,
dMatrix} /. {m1 -> m1val, m2 -> m2val, k -> kval}];
ans = StateResponse[ssM, UnitStep[t], t];
{ssM, Plot[Evaluate[ans], {t, 0, 10}, PlotRange -> All]}]
stateresp = stateSpacePlotter[a, b, c, d, 10, 100, 10]
I hope this helps
Attachments: