Error Index in position 1 exceeds array bounds (must not exceed 4).
Show older comments
I am trying to run a "for loop" for a list of numbers. I am getting the correct answers except for my last number "1.5". Here is what my error is saying:
Index in position 1 exceeds array bounds (must not exceed 4).
Error in WaveEquation (line 30)
Here is my Code:
clear all; format compact; tic
delx = 0.1;
u = 1;
r= [0.2, 0.5, 0.8, 1, 1.25, 1.5];
% r=1;
j=1;
for i = r
delt = i.^2*delx./u; % Delta Time Step Size
Tsteps = round(1./delt); % Number of Steps
x1 = zeros(Tsteps, 1./(2*delx)+2);
% Initial Conditions
x = 0:delx:.5+delx;
x1(1,:) = sin(pi*x);
% Boundary Conditions
x1(2,2:end-1) = .5*(x1(1,1:end-2)+x1(1,3:end));
x1(2,end) = x1(2,end-2); % Reflection Line
for row = 3:size(x1,1)
for col = 2:size(x1,2)-1
x1(row,col) = 2*(1-i)*x1(row, col)+i*(x1(row-1,col-1)+x1(row-1,col+1))-x1(row-2,col);
end
x1(row,end) = x1(row,end-2); % Reflection Line
end
x2 = [x1,fliplr(x1(:,1:end-3))];
fprintf('\nr =%f', i);
if (delx==.1)
dispmat = x1(1:6,1:7);
fprintf('\nExplicit Method\n')
disp(num2str(dispmat))
end
j=j+1;
end
And here is my Command Window. I am getting what I need up until r = 1.5.

Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!