Homogenuous differential equation with conditions

조회 수: 1 (최근 30일)
Kasi
Kasi 2023년 1월 31일
편집: Dyuman Joshi 2023년 1월 31일
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

답변 (1개)

Dyuman Joshi
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
i = 1×31
-8.2000 -7.2000 -6.2000 -5.2000 -4.2000 -3.2000 -2.2000 -1.2000 -0.2000 0.8000 1.8000 2.8000 3.8000 4.8000 5.8000 6.8000 7.8000 8.8000 9.8000 10.8000 11.8000 12.8000 13.8000 14.8000 15.8000 16.8000 17.8000 18.8000 19.8000 20.8000
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)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by