Your problem is on the line:
J(i+1)=J(i)+(h/6)*(dJ1+2*dJ2+2*dJ3+dJ4);
In the right-hand side of your assignment operator you use the variable J
that is never set before i
is taking the value 1. Looks like a typo to me (should it be J_0
instead?)
Also, don't forget your index i
when computing your dJ
and dZ
stuff in the for
loop.