Index in position 2 exceeds array bounds (must not exceed 1)
3 views (last 30 days)
Show older comments
I am solving a I D transient heat conduction equation (given below) and I keep getting this error, I am unable to resolve it.
ANY HELP IS APPRECIATED
u_c = zeros(n+1,1);
u_p = zeros(n+1,1);
for i = 1:n+1
u_c(i+1,1) = U_i;
end
for m = 2:T+1 % Time Loop
for i = 2:n % Space Loop
u_c(m,i+1) = u_p(m,i+1) + 0.5*(u_p(m+1,i+1)-(2*u_p(m,i+1))+u_p(m-1,i+1)) ;
end
u_p = u_c;
u_c(1,i) = ((k*u_p(1,i)) + (dx*h*U_f))/(k+(dx*h));
u_c(n,i) = ((k-(dx*h))*u_p(n-1,i))+(U_f*dx)/k;
end
0 Comments
Answers (1)
meghannmarie
on 30 Sep 2019
Edited: meghannmarie
on 30 Sep 2019
The variables u_c and u_p are vectors or the size of the second dimension is 1. Then you try to set these variables with i in the second dimension which is more than 1. Maybe first 2 lines should be this:
u_c = zeros(n+1,T+2);
u_p = zeros(n+1,T+2);
Hard to tell without the data.
See Also
Categories
Find more on Mathematics and Optimization 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!