rpms=[500,1800,2000,2200,2400,2600,2800,3000,3200,3400,3600,3800,4000,4200,4400,4600,4800,5000,5200,5400,5600,5800];
torques_engine=1.35582.*[320,325,330,340,350,355,357,359,360,360,362,363,363,362,360,355,350,345,340,327,320,310];

figure
p=plot(rpms,torques_engine);
title('Torque vs RPM')
set(p,'Color','red','LineWidth',3)
axis([min(rpms),max(rpms),0,700])


%%

rpms=[1000,1500,2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000];
torques_engine=1.35582.*[50,65,80,92,104,114,120,125,130,133,130,122,110];


figure
p=plot(rpms,torques_engine);
title('Torque vs RPM','fontsize',12,'fontweight','b')
set(p,'Color','red','LineWidth',3)
axis([min(rpms),max(rpms),0,200])
xlabel('RPM');
ylabel('Torque [N.m]');


%%
h_fig=figure;
% Throttle:
curve_throttle_1_2=[0,30,70,100];
curve_throttle_2_3=[0,35,70,100];
curve_throttle_3_4=[0,30,70,100];
curve_throttle_4_5=[0,30,75,100];
% Speed:
curve_speed_1_2=[20,20,45,45];
curve_speed_2_3=[40,40,65,65];
curve_speed_3_4=[60,60,75,75];
curve_speed_4_5=[75,75,100,100];

%,'MarkerEdgeColor','k','MarkerSize',7,'MarkerFaceColor',[1,0,0]
%area(curve_throttle_1_2,curve_speed_1_2,'FaceColor',[1,0,0],'EdgeColor',[1,0,0]);
%alpha(0.3)

% Gera a área da primeira:
patch([curve_throttle_1_2,100,0],[curve_speed_1_2,0,0],[254,204,203]./255)
hold on
% Gera a área da segunda:
patch([curve_throttle_1_2,fliplr(curve_throttle_2_3)],[curve_speed_1_2,fliplr(curve_speed_2_3)],[205,255,204]./255,'EdgeColor',[0,0,0]);
% Gera a área da terceira:
patch([curve_throttle_2_3,fliplr(curve_throttle_3_4)],[curve_speed_2_3,fliplr(curve_speed_3_4)],[204,204,254]./255,'EdgeColor',[0,0,0]);
% Gera a área da quarta:
patch([curve_throttle_3_4,fliplr(curve_throttle_4_5)],[curve_speed_3_4,fliplr(curve_speed_4_5)],[204,204,204]./255,'EdgeColor',[0,0,0]);
% Gera a área da quinta:
patch([curve_throttle_4_5,100,0],[curve_speed_4_5,120,120],[204,255,255]./255,'EdgeColor',[0,0,0]);
%alpha(0.2)
text(45,100,'gear#5','FontSize',12)
text(45,75,'gear#4','FontSize',12)
text(45,60,'gear#3','FontSize',12)
text(45,40,'gear#2','FontSize',12)
text(45,20,'gear#1','FontSize',12)

% Gera a curva 1<->2:
h_1_2=plot(curve_throttle_1_2,curve_speed_1_2,'-r','LineWidth',3);
% Gera a curva 2<->3:
h_2_3=plot(curve_throttle_2_3,curve_speed_2_3,'-g','LineWidth',3);
% Gera a curva 3<->4:
h_3_4=plot(curve_throttle_3_4,curve_speed_3_4,'-b','LineWidth',3);
% Gera a curva 4<->5:
h_4_5=plot(curve_throttle_4_5,curve_speed_4_5,'k','LineWidth',3);
% Geração da legenda:
hleg=legend([h_1_2,h_2_3,h_3_4,h_4_5],['1st<->2nd';'2nd<->3rd';'3rd<->4th';'4th<->5th'],'Location','NorthEastOutside');
set(hleg,'FontSize',12,'FontWeight','b')

xlabel('% Throttle');
ylabel('Car Speed [km/h]');
title('Gear Shifting Schedule','fontsize',12,'fontweight','b')
axis([0,100,0,120])
set(h_fig,'OuterPosition',[100,100,800,600])

%% 
h_fig=figure;
% UP shifts:
% Throttle:
curve_throttle_1_2=[0,30,65,100];
curve_throttle_2_3=[0,35,70,100];
curve_throttle_3_4=[0,30,70,100];
curve_throttle_4_5=[0,30,75,100];
% Speed:
curve_speed_1_2=[20,20,50,50];
curve_speed_2_3=[40,40,65,65];
curve_speed_3_4=[60,60,75,75];
curve_speed_4_5=[75,75,100,100];
% DOWN shifts:
% Throttle:
curve_throttle_2_1=[0,30,65,100];
curve_throttle_3_2=[0,35,70,100];
curve_throttle_4_3=[0,30,70,100];
curve_throttle_5_4=[0,30,75,100];
% Speed:
curve_speed_2_1=[15,15,40,40];
curve_speed_3_2=[35,35,60,60];
curve_speed_4_3=[55,55,70,70];
curve_speed_5_4=[70,70,90,90];
% Geração da legenda:
% Gera a área da primeira:
patch([curve_throttle_2_1,100,0],[curve_speed_2_1,0,0],[254,204,203]./255,'EdgeColor','none')
hold on

% Gera a área de indefinição 1 2:
%patch([curve_throttle_2_1,fliplr(curve_throttle_1_2)],[curve_speed_2_1,fliplr(curve_speed_1_2)],[1,0.55,0],'EdgeColor','none');

% Gera a área de indefinição 2 3:
%patch([curve_throttle_3_2,fliplr(curve_throttle_2_3)],[curve_speed_3_2,fliplr(curve_speed_2_3)],[1,0.55,0],'EdgeColor','none');

% Gera a área de indefinição 3 4:
%patch([curve_throttle_4_3,fliplr(curve_throttle_3_4)],[curve_speed_4_3,fliplr(curve_speed_3_4)],[1,0.55,0],'EdgeColor','none');

% Gera a área de indefinição 3 4:
%patch([curve_throttle_5_4,fliplr(curve_throttle_4_5)],[curve_speed_5_4,fliplr(curve_speed_4_5)],[1,0.55,0],'EdgeColor','none');

% Gera a área da segunda:
patch([curve_throttle_1_2,fliplr(curve_throttle_3_2)],[curve_speed_1_2,fliplr(curve_speed_3_2)],[205,255,204]./255,'EdgeColor','none');
% Gera a área da terceira:
patch([curve_throttle_2_3,fliplr(curve_throttle_4_3)],[curve_speed_2_3,fliplr(curve_speed_4_3)],[204,204,254]./255,'EdgeColor','none');
% Gera a área da quarta:
patch([curve_throttle_3_4,fliplr(curve_throttle_5_4)],[curve_speed_3_4,fliplr(curve_speed_5_4)],[204,204,204]./255,'EdgeColor','none');
% Gera a área da quinta:
patch([curve_throttle_4_5,100,0],[curve_speed_4_5,120,120],[204,255,255]./255,'EdgeColor','none');
% Gera a curva 1->2:
h_up_1_2=plot(curve_throttle_1_2,curve_speed_1_2,'-^r','MarkerEdgeColor','k','MarkerSize',5,'MarkerFaceColor',[1,0,0],'LineWidth',3);
% Gera a curva 2->3:
h_up_2_3=plot(curve_throttle_2_3,curve_speed_2_3,'-^g','MarkerEdgeColor','k','MarkerSize',5,'MarkerFaceColor',[0,1,0],'LineWidth',3);
% Gera a curva 3->4:
h_up_3_4=plot(curve_throttle_3_4,curve_speed_3_4,'-^b','MarkerEdgeColor','k','MarkerSize',5,'MarkerFaceColor',[0,0,1],'LineWidth',3);
% Gera a curva 4->5:
h_up_4_5=plot(curve_throttle_4_5,curve_speed_4_5,'-^k','MarkerEdgeColor','k','MarkerSize',5,'MarkerFaceColor',[0,0,0],'LineWidth',3);
% Gera a curva 2->1:
h_dn_2_1=plot(curve_throttle_2_1,curve_speed_2_1,'--vr','MarkerEdgeColor','k','MarkerSize',5,'MarkerFaceColor',[1,0,0],'LineWidth',3);
% Gera a curva 3->2:
h_dn_3_2=plot(curve_throttle_3_2,curve_speed_3_2,'--vg','MarkerEdgeColor','k','MarkerSize',5,'MarkerFaceColor',[0,1,0],'LineWidth',3);
% Gera a curva 4->3:
h_dn_4_3=plot(curve_throttle_4_3,curve_speed_4_3,'--vb','MarkerEdgeColor','k','MarkerSize',5,'MarkerFaceColor',[0,0,1],'LineWidth',3);
% Gera a curva 5->4:
h_dn_5_4=plot(curve_throttle_5_4,curve_speed_5_4,'--vk','MarkerEdgeColor','k','MarkerSize',5,'MarkerFaceColor',[0,0,0],'LineWidth',3);

%alpha(0.2)
% Geração da legenda:
hleg=legend([h_up_1_2,h_up_2_3,h_up_3_4,h_up_4_5,h_dn_2_1,h_dn_3_2,h_dn_4_3,h_dn_5_4],['1st->2nd';'2nd->3rd';'3rd->4th';'4th->5th';'2nd->1st';'3rd->2nd';'4th->3rd';'5th->4th'],'Location','NorthEastOutside');
set(hleg,'FontSize',12,'FontWeight','b')

xlabel('% Throttle');
ylabel('Car Speed [km/h]');
title('Hysteresis Gear Shifting Schedule','fontsize',12,'fontweight','b')
axis([0,100,0,120])

set(h_fig,'OuterPosition',[100,100,800,600])
