diff --git a/MATLAB/+BatteryCircuit/InputEqn.m b/MATLAB/+BatteryCircuit/InputEqn.m index 052c5bc..468c267 100644 --- a/MATLAB/+BatteryCircuit/InputEqn.m +++ b/MATLAB/+BatteryCircuit/InputEqn.m @@ -1,4 +1,4 @@ -function U = InputEqn(parameters,t,u) +function U = InputEqn(parameters,t,inputParameters) % InputEqn Compute battery inputs for the given time and input parameters % % U = InputEqn(parameters,t,inputParameters) computes the inputs to the @@ -31,15 +31,18 @@ % If u specified, interpret as variable loading scheme, where u is a % vector with an even number of elements. The first of the pair of % numbers is the magnitude of the load, the second is the duration. - loads = u(1:2:end); - durations = u(2:2:end); - times = [0 cumsum(durations)]; - % Find which load corresponds to given time - loadIndex = find(t>=times,1,'last'); - if loadIndex>length(loads) - current = loads(end); - else - current = loads(loadIndex); + for ii = 1:size(inputParameters,2) + u = inputParameters(:,ii); + loads = u(1:2:end); + durations = u(2:2:end); + times = [0; cumsum(durations)]; + % Find which load corresponds to given time + loadIndex = find(t>=times,1,'last'); + if loadIndex>length(loads) + current(ii) = loads(end); + else + current(ii) = loads(loadIndex); + end end end diff --git a/MATLAB/+BatteryCircuit/test.m b/MATLAB/+BatteryCircuit/test.m index c94c724..a5e7b5e 100644 --- a/MATLAB/+BatteryCircuit/test.m +++ b/MATLAB/+BatteryCircuit/test.m @@ -23,7 +23,7 @@ % Simulate for a variable load profile % Specified by a sequence of pairs of numbers, where the first is the load % (in Watts) and the second is the duration (in seconds). -loads = [2 10*60 1 5*60 4 15*60 2 20*60 3 10*60]; +loads = [2; 10*60; 1; 5*60; 4; 15*60; 2; 20*60; 3; 10*60]; battery.inputEqnHandle = @(P,t)BatteryCircuit.InputEqn(P,t,loads); [T,X,U,Z] = battery.simulate(3000,'printTime',60); diff --git a/MATLAB/+Model/Model.m b/MATLAB/+Model/Model.m index 099b736..635cd30 100644 --- a/MATLAB/+Model/Model.m +++ b/MATLAB/+Model/Model.m @@ -60,6 +60,7 @@ V; % Process noise variances (vector) N; % Sensor noise variances for current sensor set (vector) + x0Variance; % Initial states variance (vector) P; % Static parameters structure indices; % Structure to get indices of states, inputs, outputs by name @@ -130,6 +131,15 @@ M.N(i,1) = M.outputs(i).Noise; end + % Set up initial states variances vector + for i=1:length(M.states) + if isfield(M.states(i),'x0Variance') + M.x0Variance(i,1) = M.states(i).x0Variance; + else + M.x0Variance(i,1)= M.states(i).Noise; + end + end + % Setup indices structure M.setIndices(); end