%% INPUT -----------------------------------------------------------------+
a = 0; % left time interval limit
b = 20; % right time interval limit
N = 100; % number of points
tol = 1e-6; % tolerance
mu = [.01 .5 1 1.5 2 2.5 3 3.5 10]; % parameter range
x0 = [-2;0];
%% SOLVER ----------------------------------------------------------------+

newmap = jet(length(mu));
figure('Position',[500 500 1050 400]);
for ii = 1:length(mu)
    f = @(t,x) [x(2);-x(1)-mu(ii)*(x(1)^2-1)*x(2)]; % function f
    [t,x,error] = RKF45(a,b,x0,N,tol,f); % Runge-Kutta-Fehlberg 4th order adaptative scheme

%     figure(1); % time series
    subplot(1,4,2:4); plot(t,x(1,:),'Color',newmap(ii,:),'LineWidth',2); hold on;

%     figure(2); % phase portrait
    subplot(1,4,1); plot(x(1,:),x(2,:),'Color',newmap(ii,:),'LineWidth',2); hold on;
    
%     figure(1); % time series
%     plot(t,x(1,:),'Color',newmap(ii,:)); hold on;
% 
%     figure(2); % phase portrait
%     plot(x(1,:),x(2,:),'Color',newmap(ii,:)); hold on;
end
%% FORMAT OUTPUT ---------------------------------------------------------+
subplot(1,4,2:4); 
title('(b)','interpreter','latex');

axis([0 10 -2.5 2.5]);
ax = gca;
ax.XTick = 0:1:10;
ax.YTick = -2.5:.5:2.5;
set(ax,'TickLabelInterpreter','latex');

h = legend('$\mu = 0.01$','$0.5$','$1.0$','$1.5$','$2.0$','$2.5$','$3.0$','$3.5$','$4.0$');
set(h,'Interpreter','latex','FontSize',16,'Location','southoutside','Orientation','Horizontal','Box','Off')

set(gca,'fontsize',16)
str='$t$';
xlabel(str,'interpreter','latex','FontSize',20);
str='$x$';
ylabel(str,'interpreter','latex','FontSize',20);

subplot(1,4,1); 
title('(a)','interpreter','latex');

axis([-4 4 -8 8]);
ax = gca;
ax.XTick = -4:2:4;
ax.YTick = -8:2:8;
set(ax,'TickLabelInterpreter','latex');

% h = legend('$I^0_1$','$I^0_2$');
% set(h,'Interpreter','latex','FontSize',20,'Location','northwest')

set(gca,'fontsize',16)
str='$x$';
xlabel(str,'interpreter','latex','FontSize',20);
str='$x^{\prime}$';
ylabel(str,'interpreter','latex','FontSize',20);

tightfig;