MATLAB: Initial Value of y(0)=0

ivpsyntaxy(0)=0

How does one write a code for the IVP of y(0) = 0? The program won't accept the following. Also, can someone check my syntax for the equations I've entered? Thanks!
function ystar = Eulermethod201(n)
a=0;
b=5;
h=(b-a)/n;
t=0:h:5;%Initialize time variable
clear ystar;%wipe out old variable
ystar(0)=0;%Initial condition (same for approximation)
for i=0:length(t), %Set up "for" loop
%Calculate the derivative
k1=(-0.5*exp(t(i)/2)*sin(5*t(i))+5*exp(t(i)/2)*cos(5*t(i))-ystar(i));
ystar(i+1)=ystar(i)+h*k1;%Estimate new value of y
end
%Exact solution
y=(exp(t/2))*(sin(5*t));
%Error calculation
percent_error=100*abs(y-ystar)./y;
disp(percent_error);
%Plot approximate and exact solutions
plot(t,ystar,'b--',t,y,'r-',t,percent_error,'g');
legend('Approximate','Exact','Error');
title('Euler Approximation n=50');
xlabel('Time');
ylabel('y*(t), y(t)');

Best Answer

Unlike C language, MATLAB uses 1-based index for vector and matrix. So if you define a 10x1 vector, a=rand(10,1), you refer it as a(1), a(2) till a(10).
If you have the need to indicate some value at time==0, you will need to use some kind of offset to deal with it.