필터 지우기
필터 지우기

Index in position 2 exceeds array bounds (must not exceed 1)

조회 수: 1 (최근 30일)
Aditya Sonwane
Aditya Sonwane 2019년 9월 30일
댓글: Aditya Sonwane 2019년 10월 1일
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

답변 (1개)

meghannmarie
meghannmarie 2019년 9월 30일
편집: meghannmarie 2019년 9월 30일
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.
  댓글 수: 1
Aditya Sonwane
Aditya Sonwane 2019년 10월 1일
I understand, I have made some changes in the matrix formation of u_c and u_p and am providing ,my overall code please take a look and let me know.
%% MAIN FUNCTION %%
clc
clear all
%thickness of strip = L = 120mm = 0.12m
%u_p = previous temperature
%u_c = current temperature
%total time = T in sec
%timesteps = ts
U_i = 673; %initial medium temperature
U_f = 298; %quenching medium temperature
h = 3000; %in W/m^2-K
rho = 2.7889*10^3; %in kg/m^3
Cp = 0.7639*10^3; %in J/kg-K
k = 0.2473*10^3; %in W/m-K
lamda = k/(rho*Cp); %= (0.2473*10^3)/(2.7889*10^3*0.7639*10^3) = 0.1161*10^-3
T = 200;
L = 0.12;
n = 50;
dx = L/n;
%dt = (0.5/lamda)*dx^2;
ts = 500;
dt = T/ts;
%%%%%%%%%% END OF INPUT %%%%%%%%%%
u_p = zeros(1,n+1);%n+1 is for space and ts is for space
u_c = zeros(1,n+1);
w = solver(i, n, T, dx, h, k, U_f, U_i);
%plot(ts, w')
clc
clear all
%thickness of strip = L = 120mm = 0.12m
%u_p = previous temperature
%u_c = current temperature
%total time = T in sec
%timesteps = ts
U_i = 673; %initial medium temperature
U_f = 298; %quenching medium temperature
h = 3000; %in W/m^2-K
rho = 2.7889*10^3; %in kg/m^3
Cp = 0.7639*10^3; %in J/kg-K
k = 0.2473*10^3; %in W/m-K
lamda = k/(rho*Cp); %= (0.2473*10^3)/(2.7889*10^3*0.7639*10^3) = 0.1161*10^-3
T = 200;
L = 0.12;
n = 50;
dx = L/n;
%dt = (0.5/lamda)*dx^2;
ts = 500;
dt = T/ts;
%%%%%%%%%% END OF INPUT %%%%%%%%%%
u_p = zeros(1,n+1);%n+1 is for space and ts is for space
u_c = zeros(1,n+1);
w = solver(i, n, T, dx, h, k, U_f, U_i);
%plot(ts, w')
%% SOLVER %%
function u_c = solver(i, n, T, dx, h, k, U_f, U_i)
u_c = zeros(1,n+1);
u_p = zeros(1,n+1);
for i = 1:n+1
u_c(i+1,1) = U_i;
end
for ts = 2:T+1 % Time Loop
for i = 2:n % Space Loop
u_c(i+1) = u_p(i+1) + 0.5*(u_p(i+1)-(2*u_p(i+1))+u_p(i+1)) ;
end
u_p = u_c;
u_c(i) = ((k*u_p(i)) + (dx*h*U_f))/(k+(dx*h));
u_c(i) = ((k-(dx*h))*u_p(i))+(U_f*dx)/k;
end
end
%% PLOTTEMP %%
function plottemp(ts, u_c)
plot(ts,u_c)
title('Temperature Distribution in the aluminum strip')
xlabel('length of strip')
ylabel('temp')
end
END

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by