ss — Create continuous-time state-space model objects from A, B, C, and D matrices.
ss(A, B, C, D) creates a state-space model object from numeric system matrices. It follows MATLAB-compatible matrix-shape validation for state, input, output, and direct-feedthrough terms.
Syntax
sys = ss(A, B, C, D)
sys = ss(A, B, C, D, Ts)
sys = ss(A, B, C, D, "Ts", Ts)
sys = ss(A, B, C, D, name, value, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | NumericArray | Yes | — | State matrix with shape n-by-n. |
B | NumericArray | Yes | — | Input matrix with shape n-by-nu. |
C | NumericArray | Yes | — | Output matrix with shape ny-by-n. |
D | NumericArray | Yes | — | Feedthrough matrix with shape ny-by-nu. |
Ts | NumericScalar | No | 0.0 | Sample time (0 for continuous-time model). |
name | StringScalar | Variadic | — | Option name ('Ts' or 'SampleTime'). |
value | Any | Variadic | — | Option value. |
Returns
| Name | Type | Description |
|---|---|---|
sys | Any | State-space model object. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:ss:InvalidArgument | Arguments do not match supported ss invocation forms. | ss: invalid argument |
RunMat:ss:InvalidOption | A name/value option token is unsupported or malformed. | ss: invalid option |
RunMat:ss:InvalidSampleTime | Sample time is not a finite non-negative scalar. | ss: sample time must be a finite non-negative scalar |
RunMat:ss:InvalidDimensions | A, B, C, and D dimensions do not define a consistent state-space model. | ss: invalid state-space matrix dimensions |
RunMat:ss:UnsupportedInput | An input is complex, sparse, logical, or another unsupported model form. | ss: unsupported input |
RunMat:ss:Internal | Internal tensor/object construction failed. | ss: internal error |
How ss works
- Returns an object whose class name is
ss. - Stores
A,B,C,D,Ts,InputDelay,OutputDelay,StateName,InputName, andOutputNameproperties. - Preserves the input matrix orientations on the returned object.
- Uses continuous-time defaults with
Tsequal to0. ss(A, B, C, D, Ts)stores a finite non-negative sample time.ss(A, B, C, D, 'Ts', Ts)andss(A, B, C, D, 'SampleTime', Ts)store a finite non-negative sample time.- Numeric scalar inputs are treated as 1-by-1 matrices and are accepted only when the resulting dimensions are consistent.
- Complex, sparse, descriptor-form, uncertain, identified, and generalized models are not supported in this initial implementation.
GPU memory and residency
ss is a host-side object constructor. gpuArray matrix inputs are gathered before object construction, and the returned state-space object does not live on the GPU.
Examples
Creating a continuous-time state-space model
A = [0 1; -2 -3];
B = [0; 1];
C = [1 0];
D = 0;
G = ss(A, B, C, D);
class(G)Expected output:
ans = "ss"Reading stored state-space matrices
G = ss([0 1; -2 -3], [0; 1], [1 0], 0);
fprintf("%.0f %.0f %.0f %.0f %.0f %.0f\n", G.A(1), G.A(2), G.A(3), G.A(4), G.B(1), G.B(2));Expected output:
0 -2 1 -3 0 1Creating a discrete-time model
G = ss(0.5, 1, 1, 0, 0.1);
fprintf("%.1f\n", G.Ts);Expected output:
0.1Specifying sample time with a name-value pair
G = ss(0.5, 1, 1, 0, 'SampleTime', 0.2);
fprintf("%.1f\n", G.Ts);Expected output:
0.2How RunMat validates ss
ss validates finite real matrix inputs, state-space dimension consistency, supported name-value options, and sample-time constraints before constructing the host-side object. Unit and integration tests cover continuous and discrete constructors, property access, invalid dimensions, invalid sample times, descriptor signatures, and gpuArray gathering.
- Implementation: `crates/runmat-runtime/src/builtins/control/ss.rs`
See Correctness & Trust for the full methodology and coverage table.
Using ss with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how ss changes the result.
Run a small ss example, explain the result, then change one input and compare the output.
FAQ
Does ss simulate step or impulse responses?⌄
No. This builtin constructs a state-space object. Response functions can add ss parsing separately.
Does ss accept complex or sparse matrices?⌄
Not yet. Inputs must be finite real numeric scalars or dense matrices.
How are dimensions validated?⌄
A must be n-by-n, B must be n-by-nu, C must be ny-by-n, and D must be ny-by-nu.
Will ss(gpuArray(A), B, C, D) return a gpuArray-backed object?⌄
No. ss gathers gpuArray inputs and stores host tensors on the returned object.
Related Control functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how ss is executed, line by line, in Rust.
- View the source for ss in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.