Homogenuous differential equation with conditions
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Dyuman Joshi
on 31 Jan 2023
Edited: Dyuman Joshi
on 31 Jan 2023
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 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!