ss — Create a state-space model from A, B, C, and D matrices.
ss(A,B,C,D) constructs a host ss object. A must be square; B has the same row count as A; C has the same column count as A; and D has C's row count and B's column count. Inputs must be finite real numeric scalars or dense matrices.
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
A- Type
NumericArray- Required
- Yes
- Description
- State matrix with shape n-by-n.
B- Type
NumericArray- Required
- Yes
- Description
- Input matrix with shape n-by-nu.
C- Type
NumericArray- Required
- Yes
- Description
- Output matrix with shape ny-by-n.
D- Type
NumericArray- Required
- Yes
- Description
- Feedthrough matrix with shape ny-by-nu.
Ts- Type
NumericScalar- Required
- No
- Default
0.0- Description
- Sample time (0 for continuous-time model).
name- Type
StringScalar- Required
- Variadic
- Description
- Option name ('Ts' or 'SampleTime').
value- Type
Any- Required
- Variadic
- Description
- Option value.
Returns
sys- Type
Any- Description
- State-space model object.
Errors
RunMat:ss:InvalidArgument- When
- Arguments do not match supported ss invocation forms.
- Message
ss: invalid argument
RunMat:ss:InvalidOption- When
- A name/value option token is unsupported or malformed.
- Message
ss: invalid option
RunMat:ss:InvalidSampleTime- When
- Sample time is not a finite non-negative scalar, or an integer sample time cannot be represented exactly as double.
- Message
ss: sample time must be a finite non-negative scalar
Forms and stored model
A scalar is treated as a 1-by-1 matrix. The returned object retains each input matrix's orientation after normalization to double. It stores A, B, C, D, Ts, zero InputDelay and OutputDelay vectors, and empty StateName, InputName and OutputName cell arrays. Without Ts it is continuous-time with Ts = 0.
ss(A,B,C,D,Ts) and the Ts or SampleTime name/value forms accept a finite nonnegative scalar sample time. Option names are case-insensitive. Complex, sparse, descriptor-form, uncertain, identified, and generalized models are outside this implementation.
Typed-integer matrices and sample times are RunMat-only extensions. Values must cross the binary64 model boundary exactly. An inexact matrix reports RunMat:ss:InvalidMatrix; an inexact sample time reports RunMat:ss:InvalidSampleTime. Explicit gpuArray input is a separate RunMat-only extension; ordinary automatically resident inputs may gather in either mode.
Execution and placement
Extension admission precedes provider access. Supported resident matrices and sample times then gather through their owning provider and are checked for exact integer conversion at the host model boundary. Construction validates dimensions and returns a new value-semantic host object. Host tensor storage may be shared until copy-on-write mutation. There is no GPU kernel or fusion; provider access may suspend.
Examples
Read stored matrices in column-major order
G = ss([0 1; -2 -3], [0; 1], [1 0], 0);Continuous state-space model
A = [0 1; -2 -3]; B = [0; 1]; C = [1 0]; G = ss(A,B,C,0);Discrete sample time
G = ss(0.5,1,1,0,0.1);Named sample time
G = ss(0.5,1,1,0,'SampleTime',0.2);Integer matrix extension
G = ss(int16(1),int16(2),int16(3),int16(4));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
How are matrix dimensions validated?⌄
A must be n-by-n, B n-by-nu, C ny-by-n, and D ny-by-nu. Their stored orientations are preserved.
Does ss simulate a response?⌄
No. It constructs a model; step and impulse perform response calculations.
Are complex and sparse matrices supported?⌄
No. This constructor currently requires finite real dense matrices.
Is the result GPU-resident?⌄
No. Accepted resident inputs are gathered and the model owns host-side double matrices.
Related Control functions
Source you can read
Every RunMat function's source is public. 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 a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.