MATLAB: Index must be a positive integer or logical.

error

I am getting the error : "Attempted to access x(1.01); index must be a positive integer or logical."
Help would be appreciated please 🙂
clc, clear all func = @(t,x) -t*x;
t = 0; x = 1; h = 0.01; N = 10 tarrays = zeros(1,N); xarrays = zeros(1,N);
for i = 1:h:N
x(i+1) = x(i) + h.*func(t(i),x(i));
tarrays = t(i)
xarrays = x(i+1)
end

Best Answer

Got the answer guys
I change the step into a length values of the steps :)
t = 0; %Initial Value

x = 1; %Initial Value
h = 0.1; %Step size
N = 10;
Nvec = [1:h:N];
step = length(Nvec);
tarrays = zeros(1,N)
xarrays = zeros(1,N)
for i = 1:step
Related Question