Index in position 1 is invalid- attempting to perform Laplace's equation
1 view (last 30 days)
Show older comments
I've been trying to use Laplace's equation to model the temperature gradient in the cross section of two tubes, here's the code:
[X,Y,T] = meshgrid(0:0.1:10, 0:0.1:10, zeros);
for k = 1:1000
for i = 1:100
for j = 1:100
if ((0.1*i)-6)^2 + ((0.1*j)-5)^2 <= 6.25
T(i,j) = 100;
end
if ((0.1*i)-5)^2 + ((0.1*j)-5)^2 <= 25
T(i,j) = 0;
end
T(i,j) = 0.25*(T((0.1*i)-1,(0.1*j))+T((0.1*i)+1,(0.1*j))+T((0.1*i),(0.1*j)-1)+T((0.1*i),(0.1*j)+1));
end
end
end
surf(X,Y,T)
Everything works fine before I insert line 11, and when I do, I get the error message
"Index in position 1 is invalid. Array indicies must be positive integers or logical values".
For the record, I've tried doing it without multiplying all the variables in the equation by 0.1, that was just one of my many attempts to get this to work.
What am I doing wrong, and what should I do to fix it?
6 Comments
Answers (1)
Alan Stevens
on 19 Nov 2020
In your loops, 0.1i and 0.1j will result in non integer values for most values of i and j. Indices in T(i,j) etc must be integers (>=1), so T(0.1*i-1,0.1j) could have indices that are non-integer (and even negative), so are inadmissable.
0 Comments
See Also
Categories
Find more on Matrix Indexing 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!