function dependant on previous value min for loop with different size
Ältere Kommentare anzeigen
this is my code, in the for loop running in t im trying to calculate I_batt which allows me to calculate the SOC which i then use to calculate the I_batt for the next t value, problem is I_batt has a different size and it gives me an error. how do i fix this?
clc;clear;close all;
%% fixed variables
theta = [-5:1:5]; % gradient of road in degrees
m = 1500; % mass of vehicle in kg
g = 9.81; % gravitational acc
Cr = 0.02; % rolling resistance coefficient
v_veh = 30; % velocity of vehicle in m/s
air_dens = 1.23; % air density in kg/m^3
Cd = 0.3; % drag coefficient
A = 1; % area of veh exposed to air in m^2
p_tyre = 1; %tyre pressure in Bar
Cr = 0.005+(1./p_tyre).*(0.01+0.0095.*(v_veh./100).^2); %rolling resistance depending on tyre pressure and velocity
Fc_max = 50000; %max power output of fuel cell in N
Voc = 4; % open circuit voltage in V
Ah = 70; % capacity of battery in Ah
Max_charge = Ah.*3600; %converting capacity of battery to Coulombs
%% for loop of simulation for hybrid vehicle
for n = 1:11
theta_n = theta(n); % gradient of road at each n
Fr(n) = m.*g.*Cr; % Resistance force due to rolling
Fa(n) = 0.5.*air_dens.*Cd.*A.*v_veh.^2; % resistance due to air drag
Fg(n) = m.*g.*sind(theta_n); % gradient resistance
Ft(n) = Fr(n)+Fa(n)+Fg(n);
Pt(n) = Ft(n).*v_veh;
if Pt<Fc_max
R0 = 1e-4;
C1 = 2e4;
R1 = 7.8e-4;
C2 = 2e5;
R2 = 3e-3;
Vh = -2e-3;
else
R0 = 8e-5;
C1 = 2e4;
R1 = 8e-4;
C2 = 2.2e5;
R2 = 3e-4;
Vh = 1e-3;
end
for t = 1:100
SOC{1} = 0.7;
if Pt < 0
SOC(t) = SOC(1);
end
if Pt(n)<Fc_max && Pt(n)>0
preq(n) = Fc_max - Pt(n);
Q{t} = SOC{t}.*Max_charge;
Vc1{t} = Q{t}./C1;
Vc2{t} = Q{t}./C2;
I_batt{t+1} = ((Voc-Vc1{t}-Vh+Vc2{t}-Vh(n))-sqrt((Voc-Vc1{t}-Vh+Vc2{t}-Vh(n)).^2-4.*R0(n).*preq(n)))./(2.*R0(n));
dSOC = -I_batt{t}./Q{t};
SOC{t+1} = SOC{t}+dSOC;
end
end
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Propagation and Channel Models finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!