Homogenuous differential equation with conditions
조회 수: 1 (최근 30일)
이전 댓글 표시
Find and draw the first 22 terms of the solution of the homogeneous differential equation with the initial conditions: y[−1] = 0.6, y[−2] =
-8.2.
I dont understand what went wrong here?Dont understand how this work.
j=22;
y=[-8.2,0.6];
for i= -8.2:j+0.6
y(i)= 0.19*y(i-1)-0.36*y(i-2)+(0.31)^(i-3);
end
k=[-2:21];
stem(k,y);
"Array indices must be positive integers or logical values" problem
댓글 수: 0
답변 (1개)
Dyuman Joshi
2023년 1월 31일
편집: Dyuman Joshi
2023년 1월 31일
j=22;
y=[-8.2,0.6];
As you can see below, you are using non integer values as an index, which is not possible.
i = -8.2:j+0.6
MATLAB accepts only Natural numbers as index values. [1 2 3 4 ....] (or logical values, as the error clearly states)
Change the loop variable values
for i=3:22
y(i)= 0.19*y(i-1)-0.36*y(i-2)+(0.31)^(i-3);
end
k=[-2:19];
stem(k,y)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!