%% Specify Input Order of State Variables
% Specify input order of the state variables to choose which variables are being returned when eliminating DAEs.
% Create a system of four DAEs in four state variables V_ac(t), V1(t), V2(t), and I(t). The system also contains symbolic parameters L, R, and V0.

syms V_ac(t) V1(t) V2(t) I(t) L R V0
eqs = [V_ac(t) == V1(t) + V2(t),
       V1(t) == I(t)*R,
       V2(t) == L*diff(I(t),t),
       V_ac(t) == V0*cos(t)]
vars = [V_ac(t),I(t),V1(t),V2(t)]

% Use reduceRedundancies to eliminate redundant equations and variables. reduceRedundancies prioritizes to keep the state variables in the vector vars starting from the first element.

[newEqs,newVars] = reduceRedundancies(eqs,vars)

% Here, reduceRedundancies returns a reduced equation in term of the variable I(t).
% When multiple ways of reducing the DAEs exist, specify a different input order of the state variables to choose which variables are being returned. Specify another vector that contains a different order of the state variables. Eliminate the DAEs again.

vars2 = [V_ac(t),V1(t),V2(t),I(t)]
[newEqs,newVars] = reduceRedundancies(eqs,vars2)

% Here, reduceRedundancies returns a reduced equation in term of the state variable V1(t).
%
% Copyright 2018 The MathWorks, Inc.