` function [tout,Aout] = ivp_RK4(t0,A0,h,n_out,i_out) tout = zeros(n_out+1,1); tout(1) = 0; Aout = zeros(n_out+1,1); Aout(1) = 1; t = t0; A = A0; for j=2:n_out+1; i=1:i_out; k1 = A(i)-exp(-2*t); k2 =(A(i)+h/2)*k1-exp(-2*(t+h/2)) ; k3 =(A(i)+h/2)*k2-exp(-2*(t+h/2)); k4 = (A(i)+h/2)*k3-exp(-2*(t+h/2)); A = A + (h/6)*(k1 + 2*k2 + 2*k3 + k4); t = t + h; end tout(j) = t; Aout(j) = A; plot(t,A) end`

Index exceeds the number of array elements (1).

Error in ivp_RK4 (line 7)

k1 = A(i+1)-exp(-2*t);

## Best Answer