MATLAB: Do I get a linear algebra error when trying to create a variable gear ratio block using Simscape language

gearSimscapetransmissionvariable

I am trying to construct a simple variable gear ratio block using the Simscape language by adapting the code from the gear box in the Simscape foundation library. However, using a physical signal as the gear ratio results in the following error:
Nonlinear solver: Linear Algebra error. Failed to solve using iteration matrix.
Initial conditions solve failed to converge.
Replacing the gear ratio with a parameter (rather than an input) gets rid of the problem.

Best Answer

When the ratio is a constant value, this allows the solver to make assumptions and simplify the equations. However, when the ratio comes from a signal, the equations of the system become index-2 DAE (Differential Algebraic Equations) that the Simscape solver cannot solve (due to its inherent limitations).
To work around this limitation, include stiffness and damping in the equations while modeling this system. The ‘Variable Ratio Transmission’ block in SimDriveline implements exactly this. If you would like to implement this behavior in an ssc file, the equations would look like the following:
let
phiDot = rotation_sign*ratio*F.w - B.w;
in
phi.der == phiDot;
tB == -kv*phiDot - kp*phi;
tF == -rotation_sign*ratio*tB;
end