INITIAL_RESPONSE

The initial response describes how a state-space system evolves from a non-zero initial state when there is no external forcing input.

For a linear system with zero input, the dynamics are governed by

\dot{x}(t) = A x(t), \quad y(t) = C x(t)

with the initial condition x(0) = X_0. This is useful for studying the natural modes of the system, including decay, oscillation, or growth due solely to the initial state. The wrapper returns a 2D array with time in the first row and one output row for each system output channel.

Excel Usage

=INITIAL_RESPONSE(A, B, C, D, initial_state, timepts)
  • A (list[list], required): System dynamics matrix (nxn).
  • B (list[list], required): Control matrix (nxm).
  • C (list[list], required): Output matrix (pxn).
  • D (list[list], required): Feedforward/feedthrough matrix (pxm).
  • initial_state (list[list], required): Initial condition state vector (length n).
  • timepts (list[list], optional, default: null): Optional time vector or scalar simulation duration (in seconds).

Returns (list[list]): A 2D array where the first row contains the time vector and each subsequent row contains one output channel of the initial-condition response.

Example 1: Simple unforced decay

Inputs:

A B C D initial_state timepts
-1 -2 5 6 8 0 1 0 0.1
3 -4 7 0

Excel formula:

=INITIAL_RESPONSE({-1,-2;3,-4}, {5;7}, {6,8}, {0}, {1;0}, {0,0.1})

Expected output:

Result
0 0.1
6 7.13947

Python Code

Show Code
import control as ct
import numpy as np

def initial_response(A, B, C, D, initial_state, timepts=None):
    """
    Compute the initial condition response for a state-space system.

    See: https://python-control.readthedocs.io/en/latest/generated/control.initial_response.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        A (list[list]): System dynamics matrix (nxn).
        B (list[list]): Control matrix (nxm).
        C (list[list]): Output matrix (pxn).
        D (list[list]): Feedforward/feedthrough matrix (pxm).
        initial_state (list[list]): Initial condition state vector (length n).
        timepts (list[list], optional): Optional time vector or scalar simulation duration (in seconds). Default is None.

    Returns:
        list[list]: A 2D array where the first row contains the time vector and each subsequent row contains one output channel of the initial-condition response.
    """
    try:
      def to_row_list(values):
        arr = np.asarray(values)
        if arr.ndim == 0:
          return [float(arr)]
        return [float(value) for value in arr.reshape(-1)]

      def flatten_to_1d(x):
        if not isinstance(x, list):
          return [float(x)] if str(x) != "" else []
        flat = []
        for row in x:
          if isinstance(row, list):
            for val in row:
              if str(val) != "":
                flat.append(float(val))
          elif str(row) != "":
            flat.append(float(row))
        return flat

      A_arr = np.array(A, dtype=float)
      B_arr = np.array(B, dtype=float)
      C_arr = np.array(C, dtype=float)
      D_arr = np.array(D, dtype=float)

      if A_arr.ndim != 2 or A_arr.shape[0] != A_arr.shape[1]:
        return "Error: A must be a square 2D matrix"

      sys = ct.ss(A_arr, B_arr, C_arr, D_arr)
      x0_arr = np.array(flatten_to_1d(initial_state), dtype=float)

      if x0_arr.shape[0] != A_arr.shape[0]:
        return f"Error: Initial state vector must have length {A_arr.shape[0]} to match states"

      t_in = flatten_to_1d(timepts) if timepts is not None else None
      if t_in is not None and len(t_in) == 1:
        t_in = float(t_in[0])
      elif t_in and len(t_in) == 0:
        t_in = None

      resp = ct.initial_response(sys, T=t_in, X0=x0_arr)
      t_list = to_row_list(resp.time)
      outputs = np.asarray(resp.outputs)

      if outputs.ndim <= 1:
        return [t_list, to_row_list(outputs)]

      return [t_list] + [to_row_list(row) for row in outputs]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

System dynamics matrix (nxn).
Control matrix (nxm).
Output matrix (pxn).
Feedforward/feedthrough matrix (pxm).
Initial condition state vector (length n).
Optional time vector or scalar simulation duration (in seconds).