Equation exceeding matrix dimensions
이전 댓글 표시
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))
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!