I am trying to make a function to solve an equation using Eulers with multiple step sizes. When I go to the command window and input part2a(1.0,0.5,0.1,0.05)
I get the error message:
Subscript indices must either be real positive integers or logicals.
Error in part2a (line 10)
f(t(j),y(j))=(7.2.*(sin(t(j))).^2)-0.208333.*(1+y(j)).^1.5;
I understand people have asked similar questions but I haven't been able to get any of their answers to work.
function part2a(h1,h2,h3,h4)
t=0;
tf=10;
n1=(tf-t)/h1;
n2=(tf-t)/h2;
n3=(tf-t)/h3;
n4=(tf-t)/h4;
y=0;
for j=1:n1
f(t(j),y(j))=(7.2.*(sin(t(j))).^2)-0.208333.*(1+y(j)).^1.5;
x=f(t(j),y(j));
t(j+1)=t(j)+h1;
y1(j+1)=y(j)+h1*x;
end
for j=1:n2
f(t(j),y(j))=(7.2.*(sin(t(j))).^2)-0.208333.*(1+y(j)).^1.5;
x=f(t(j),y(j));
t(j+1)=t(j)+h2;
y2(j+1)=y(j)+h2*x;
end
for j=1:n3
f(t(j),y(j))=(7.2.*(sin(t(j))).^2)-0.208333.*(1+y(j)).^1.5;
x=f(t(j),y(j));
t(j+1)=t(j)+h3;
y3(j+1)=y(j)+h3*x;
end
for j=1:n4
f(t(j),y(j))=(7.2.*(sin(t(j))).^2)-0.208333.*(1+y(j)).^1.5;
x=f(t(j),y(j));
t(j+1)=t(j)+h4;
y4(j+1)=y(j)+h4*x;
end
t1=0:h1:10;
t2=0:h2:10;
t3=0:h3:10;
t4=0:h4:10;
plot(t1,y1,t2,y2,t3,y3,t4,y4);
xlabel('Time in days');
ylabel('Change in depth of the tank in meters');
end