Array indices must be positive integers or logical values.
Show older comments
h = 0.2;
T = 4:h:8
X_s=[5.87 -4.23 -2.55 -0.89 0.67 2.09 3.31 4.31 5.06 5.55 5.78 5.77 5.52 5.08 4.46 3.72 2.88 2.00 1.10 .23 -0.59]
for X=4.2:0.2:7.8
k=[X]
x=(((k/(0.2))-(4/(0.2))))+1
V = ((X_s((x)+1))-(X_s((x)-1)))/(2*h)
end
Trying to get the for loop to spit out an array of answers for a central diffrencing problem but cannot get the loop to run without an array error. when I do the math I'm seeing whole positive integers being imputed. Not sure whats going on and would appreciate help.
Accepted Answer
More Answers (1)
floating point problem;
try to use x = round(k/0.2 - 4/0.2 + 1)
k =
4.200000000000000
x =
2
k =
4.400000000000000
x =
3
k =
4.600000000000001
x =
4
k =
4.800000000000001
x =
5.000000000000004
k =
5
x =
6
k =
5.200000000000000
x =
7
k =
5.400000000000000
x =
8
k =
5.600000000000001
x =
9
k =
5.800000000000001
x =
10.000000000000004
Categories
Find more on Logical 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!