clear;clc;close all;
% Created by Razman Ayop
% on 27 September 2026
% Note that the value is not fully verified
Rafa=0.0367; % AFA rate (RM/kWh)
E=0:2000;
for i=1:length(E)
Cpre(i)=domesticPre(E(i));
Cgen(i)=domesticGeneral(E(i),Rafa);
CtouP(i)=domesticToU(E(i),0,Rafa);
CtouOP(i)=domesticToU(0,E(i),Rafa);
C01(i)=Cgen(i)-Cpre(i);
C02p(i)=CtouP(i)-Cpre(i);
C02op(i)=CtouOP(i)-Cpre(i);
C12p(i)=CtouP(i)-Cgen(i);
C12op(i)=CtouOP(i)-Cgen(i);
C01u(i)=(Cgen(i)-Cpre(i))/Cpre(i)*100;
C02pu(i)=(CtouP(i)-Cpre(i))/Cpre(i)*100;
C02opu(i)=(CtouOP(i)-Cpre(i))/Cpre(i)*100;
C12pu(i)=(CtouP(i)-Cgen(i))/Cgen(i)*100;
C12opu(i)=(CtouOP(i)-Cgen(i))/Cgen(i)*100;
end
plot(E,Cpre,'linewidth',1.5);
hold on;
plot(E,Cgen,'linewidth',1.5);
plot(E,CtouP,'--','linewidth',1.5);
plot(E,CtouOP,'--','linewidth',1.5);
grid on;
xlabel('Energy, E (kWh)');
ylabel('Charge, C (RM)');
legend('Previous Domestic Tariff','New Domestic General Tariff',...
'New Domestic ToU All Peak','New Domestic ToU All Off-Peak',...
'Location','northwest');
annotation('textbox',...
[0.15 0.29 0.2 0.056],...
'String', ['AFA = RM ' num2str(Rafa)],...
'FontSize', 16,...
'LineStyle','none',...
'FitBoxToText','off');
figure;
plot(E,Cpre,'linewidth',1.5);
hold on;
plot(E,Cgen,'linewidth',1.5);
plot(E,CtouP,'--','linewidth',1.5);
plot(E,CtouOP,'--','linewidth',1.5);
grid on;
xlabel('Energy, E (kWh)');
ylabel('Charge, C (RM)');
legend('Previous Domestic Tariff','New Domestic General Tariff',...
'New Domestic ToU All Peak','New Domestic ToU All Off-Peak',...
'Location','northwest');
annotation('textbox',...
[0.15 0.29 0.2 0.056],...
'String', ['AFA = RM ' num2str(Rafa)],...
'FontSize', 16,...
'LineStyle','none',...
'FitBoxToText','off');
xlim([0,900]);
figure;
plot(E,C01,'linewidth',1.5);
hold on;
plot(E,C02p,'linewidth',1.5);
plot(E,C02op,'linewidth',1.5);
plot(E,C12p,'linewidth',1.5);
plot(E,C12op,'linewidth',1.5);
grid on;
xlabel('Energy, E (kWh)');
ylabel('Charge Different, dC (RM)');
legend('General vs Previous','ToU All Peak vs Previous',...
'ToU All Off-Peak vs Previous','ToU All Peak vs General',...
'ToU All Off-Peak vs General','Location','northwest');
annotation('textbox',...
[0.18 0.63 0.36 0.056],...
'String', ['AFA = RM ' num2str(Rafa)],...
'FontSize', 16,...
'LineStyle','none',...
'FitBoxToText','off');
figure;
plot(E,C01u,'linewidth',1.5);
hold on;
plot(E,C02pu,'linewidth',1.5);
plot(E,C02opu,'linewidth',1.5);
plot(E,C12pu,'linewidth',1.5);
plot(E,C12opu,'linewidth',1.5);
grid on;
xlabel('Energy, E (kWh)');
ylabel('Charge Different, dC (%)');
legend('General vs Previous','ToU All Peak vs Previous',...
'ToU All Off-Peak vs Previous','ToU All Peak vs General',...
'ToU All Off-Peak vs General','Location','southeast');
annotation('textbox',...
[0.14 0.86 0.36 0.056],...
'String', ['AFA = RM ' num2str(Rafa)],...
'FontSize', 16,...
'LineStyle','none',...
'FitBoxToText','off');
function C=domesticPre(E)
% Define TNB thresholds (cumulative limits) and rates
b1 = 200; b2 = 300; b3 = 600; b4 = 900;
r1 = 0.218; r2 = 0.334; r3 = 0.516; r4 = 0.546; r5 = 0.571;
C = r1 .* ( E.*(E <= b1) + b1.*(E > b1) ) ...
+ r2 .* ( (E - b1).*(E > b1 & E <= b2) + (b2 - b1).*(E > b2) ) ...
+ r3 .* ( (E - b2).*(E > b2 & E <= b3) + (b3 - b2).*(E > b3) ) ...
+ r4 .* ( (E - b3).*(E > b3 & E <= b4) + (b4 - b3).*(E > b4) ) ...
+ r5 .* ( (E - b4).*(E > b4) );
end
function C=domesticGeneral(E,Rafa)
%% Energy Range
Ekwttb=300; % Renewable energy fund energy (kWh)
Ex=800; % Energy limit (kWh)
%% Rate
Rkwttb=0.016; % Renewable energy fund rate
Rst=0.008; % Retail charge rate
Cr=10; % Retail Charge (RM/month)
Reei = EEI(E);
if E<=1500
Re=0.2703; % Energy Charge Rate (RM/kWh)
Rc=0.0455; % Capacity Charge Rate (RM/kWh)
Rn=0.1285; % Capacity Charge Rate (RM/kWh)
else
Re=0.3703; % Energy Charge Rate (RM/kWh)
Rc=0.0455; % Capacity Charge Rate (RM/kWh)
Rn=0.1285; % Capacity Charge Rate (RM/kWh)
end
C=E*(Re+Rc+Rn+Reei)...
+(E>Ekwttb)*Rkwttb*E*(Re+Rc+Rn+Rafa)...
+(E>Ex)*(Cr+E*Rafa...
+Rst*((E-Ex)*(Re+Rc+Rn+Reei+Rafa)));
end
function C=domesticToU(Ep,Eop,Rafa)
%% Energy Range
Ekwttb=300; % Renewable energy fund energy (kWh)
Ex=800; % Energy limit (kWh)
E=Ep+Eop; % Total Energy (kWh)
Etax=E-Ex; % Taxable Energy (kWh)
if Etax<=Eop
Eop_tax=Etax;
Ep_tax=0;
else
Eop_tax=Eop;
Ep_tax=Etax-Eop;
end
%% Rate
Rkwttb=0.016; % Renewable energy fund rate
Rst=0.008; % Retail charge rate
Cr=10; % Retail Charge (RM/month)
Reei = EEI(E);
if E<=1500
Rep=0.2852; % Peak Energy Charge Rate (RM/kWh)
Reop=0.2443; % Off-Peak Energy Charge Rate (RM/kWh)
Rc=0.0455; % Capacity Charge Rate (RM/kWh)
Rn=0.1285; % Capacity Charge Rate (RM/kWh)
else
Rep=0.3852; % Peak Energy Charge Rate (RM/kWh)
Reop=0.3443; % Off-Peak Energy Charge Rate (RM/kWh)
Rc=0.0455; % Capacity Charge Rate (RM/kWh)
Rn=0.1285; % Capacity Charge Rate (RM/kWh)
end
C=E*(Rc+Rn+Reei)+Ep*Rep+Eop*Reop...
+(E>Ekwttb)*Rkwttb*(E*(Rc+Rn+Rafa)+Ep*Rep+Eop*Reop)...
+(E>Ex)*(Cr+E*Rafa+...
Rst*(((E-Ex)*(Rc+Rn+Reei)+Ep_tax*Rep+Eop_tax*Reop)));
end
function Reei = EEI(E)
Reei = zeros(size(E));
Reei(E >= 1 & E <= 200) = -0.250;
Reei(E > 200 & E <= 250) = -0.245;
Reei(E > 250 & E <= 300) = -0.225;
Reei(E > 300 & E <= 350) = -0.210;
Reei(E > 350 & E <= 400) = -0.170;
Reei(E > 400 & E <= 450) = -0.145;
Reei(E > 450 & E <= 500) = -0.120;
Reei(E > 500 & E <= 550) = -0.105;
Reei(E > 550 & E <= 600) = -0.090;
Reei(E > 600 & E <= 650) = -0.075;
Reei(E > 650 & E <= 700) = -0.055;
Reei(E > 700 & E <= 750) = -0.045;
Reei(E > 750 & E <= 800) = -0.040;
Reei(E > 800 & E <= 850) = -0.025;
Reei(E > 850 & E <= 900) = -0.010;
Reei(E > 900 & E <= 1000) = -0.005;
Reei(E > 1000) = 0.0;
end