You pass "ICs(z)" and "timeVector" to "eulersub". In the function, they get the names a and b. But a and b are never referenced in "eulersub". So for all initial conditions you pass to the function, you work with y(0) = -40 and a time interval between -5 and 5.
Maybe you mean
ICs = zeros(4,1);
ICs(1) = -5;
ICs(2) = -2;
ICs(3) = 2;
ICs(4) = 5;
timeVector = linspace(0,15,1001);
vecSize = numel(timeVector);
outputValues = zeros(4,vecSize);
for z=1:4
outputValues(z,:) = eulersub(ICs(z), timeVector);
end
plot(timeVector,outputValues)
function y = eulersub(y0,timeVector)
x=timeVector;
y = zeros(size(x));
y(1)=y0;
n = numel(y);
for i=1:n-1
f = 3*x(i).^2+2*x(i)-12;
y(i+1) = y(i) + (x(i+1)-x(i)) * f;
end
end