I get a ??? Index exceeds matrix dimensions. error for the last line in the code. I am trying to define an equation u(i+1) that includes u(i) and u(i-1) (which is itself in a previous iteration) but ran into this problem.
i = 2:4000; p0 = 10; t1 = 5; dt = 0.05;t = dt*i;p(1) = p0*dt/t1;p(i) = ... (p0*t/t1) .* (0 <= t & t < t1 ) + ... (p0) .* (t1 <= t & t < 2*t1 ) + ... (-p0*t/t1+3*p0) .* (2.*t1 <= t & t <= 3*t1) + ... (0) * (t > 3*t1);u0 = 0; ud0 = 0; udd0 = 10;un1 = u0 - dt*ud0 + (dt^2)*udd0/2;u(1) = (p0 - un1 - u0);u(2) = (p(1) - u0 - u(1));u(i+1) = (p(i) - u(i-1) - u(i));plot(t,u(i+1))
Best Answer