old = sympref('HeavisideAtOrigin', 1);
[t, x] = ode45(@nonlinearSystem, tspan, x0);
[~, Rh, u] = nonlinearSystem(t, x);
plot(t, x, 'linewidth', 1.5, 'Color', [0.8500, 0.3250, 0.0980])
grid on, ylabel x(t), title('Response, x(t)')
plot(t, Rh, 'linewidth', 1.5, 'Color', [0.9290, 0.6940, 0.1250])
grid on, ylabel Rh(t), title('Piecewise function, Rh')
plot(t, u, 'linewidth', 1.5, 'Color', [0.4660, 0.6740, 0.1880])
grid on, ylabel u(t), title('Control action, u'), xlabel t
function [dx, Rh, u] = nonlinearSystem(t, x)
Rh = Rh1 + (Rh2 - Rh1).*heaviside(t - h) + (Rh3 - Rh2).*heaviside(t - 2*h);
Kah = Rh.*W.*exp(-a*(h - 2*t));
sig = sign(x).*(abs(x)).^expn;
u = (uu - x.^3)./(1 + x.^2);
dx = x.^3 + (1 + x.^2).*u + d;