%% R-Index in Frequency Band for System with Complex Coefficients
% For systems with complex coefficients, getSectorIndex can return indices at a negative or a positive frequency depending on the fband you specify.
% Load a state-space model with complex coefficients and complex sector matrix.

load dataSysQ sys Q

% Compute the R-index and its frequency with a relative accuracy of 0.0001%. Also, specify fband = [1,10] to compute the index in the frequency interval [–10,–1] ∪ [1,10].

[R,FX] = getSectorIndex(sys,Q,1e-6,[1,10])

% In this interval, sys achieves an index of 1.5811 at a negative frequency value of –7.2320 rad/s. Use sectorplot to plot the indices in this range.

opt = sectorplotoptions;
opt.FreqScale = 'Linear';
opt.IndexScale = 'Linear';
w = linspace(-10,10,1000);
sectorplot(sys,Q,w,opt)

% Now compute the index in the frequency interval [–5,–1] ∪ [1,5]. To do so, specify fband = [1,5].

[r,f] = getSectorIndex(sys,Q,1e-6,[1,5])

% In this interval, sys achieves an index of 1.4630 at a positive frequency value of 2.2499 rad/s. Plot the indices in this range to confirm the result.

w = linspace(-5,5,500);
sectorplot(sys,Q,w,opt)

% Copyright 2021 The MathWorks, Inc.