MATLAB: Index exceeds the number of array elements (1).

arrayelementsexceedsindexMATLABnumber

I'm doing a lab for a math class and am asked to evaluate a 2nd order differential equation using Euler's Method and ODE45. My code snippet is below.
function ex_with_2eqs
t0 = 0; tf = 45; Y0 = [1;0];
[t,Y] = ode45 (@f,[t0,tf],Y0,[]);
[te,Ye] = euler(@f,[t0,tf],1,600);
y = Y(:,1); v = Y(:,2);
end
% --------------------------------------
function dYdt = f(t,Y)
y = Y(1); v = Y(2);
dYdt = [v; -4*sin(t)-(6*(y^2)*v)-8*y]; %Changed 6*v to 6*y^2*v
end
except everytime I attempt to run it I get:
Index exceeds the number of array elements (1).
Error in LAB04ex2d>f (line 9)
y = Y(1); v = Y(2);
Error in euler (line 25)
y(:,n+1) = y(:,n) + h*f(t(n),y(:,n)); % implement Euler's
method
Error in LAB04ex2d (line 4)
[te,Ye] = euler(@f,[t0,tf],1,600);
If I remove [te,Ye] = euler(@f,[t0,tf],1,600); it runs fine. So I know it has to do with that snippet, but I'm not sure why. The Euler file I have has worked for every other lab I've done except this one. I'm not sure what's going wrong.

Best Answer

In
[te,Ye] = euler(@f,[t0,tf],1,600);
Changed 1 to Y0 to establish a vector length of 2 instead of 1 given Y0 = [1;0].
Related Question