# I am getting following error while running a program. "

2 views (last 30 days)
Nikhil Chaudhari on 10 Mar 2020
Answered: Esen Ozbay on 10 Mar 2020
function [P_eng, P_elecmach] = fcn(v_veh, P_tractive, SOC)
%define variables
P_eng_min = 10; %kW
P_eng_max = 80; %kW
R_wheel = 0.2794; %m
G_diff = 0.25; %Unit less
G_trans_min = 0.3; %Unit less
W_eng_min = 16.6667; %revolutions per second
Scale = 1;
% The first thing to check is whether the W_eng (Engine Speed) is below
% its minimum level. The minimum engine speed which correspond to the
% minimum engine power level is 1000 rpm or 16.6667 rps.
% That will correspond to around 2.2 m per second or 131 m per minute.
v_veh_min = R_wheel * G_diff * G_trans_min * W_eng_min * 2 * pi;
% 2.1944 = 0.2794 * 0.25 * 0.3 * 16.6667 * 2 * pi
% if v_veh < v_veh_min
% P_eng = 0;
% P_elecmach = P_tractive;
%When P_tractive = 0, P_eng = 0
% P_elecmach = 0
%This means that vehicle is stationary
%When P_tractive < 0, P_eng = 0
% P_elecmach = P_tractive (negative value)
%This means that vehicle is stationary
if v_veh < v_veh_min
P_eng = 0;
P_elecmach = P_tractive; %P_elecmach >0 => battery is discharging
elseif P_tractive < 10
P_eng = 0;
P_elecmach = P_tractive; %P_elecmach >0 => battery is discharging
elseif P_tractive > 80
P_eng = P_eng_max;
P_elecmach = P_tractive - P_eng_max; %P_elecmach >0 => battery is discharging
else %P_tractive > 10 && P_tractive < 80
P_elecmach = (-1)*(P_eng_max - P_tractive)*(0.6-SOC)*Scale;
P_eng = P_tractive - P_elecmach;
end
return
%%Error message
Function 'Power Management Strategy' (#530.1490.1529), line 46, column 22:
"(-1)*(P_eng_max - P_tractive)*(0.6-SOC)"
Size mismatch (size [1 x 1] ~= size [3 x 1]).
The size to the left is the size of the left-hand side of the assignment.
Function 'Power Management Strategy' (#530.1547.1552), line 47, column 9:
"P_eng"

Esen Ozbay on 10 Mar 2020
You need to tell us what SOC is, but you probably input an array into the function while you were running it. SOC should be a scalar number.