I'm getting the error "Array indices must be positive integers or logical values." and it seems like I structures the for loop to handle the equations. Can anyone help me with this?

1 回表示 (過去 30 日間)
ds=zeros(length(y),1);
dAs=zeros(length(y),1);
Ac=zeros(length(y),1);
for j=1:N
t1=(t(y(j))+t(y(j+1/2)))/2; %average thickness of CV on side closer to y=0
t2=(t(y(j-1/2))+t(y(j)))/2; %avgerage thickness of CV on side closer to y=L
ds(j)=sqrt((t(y(j+1))-t(t(j-1))).^2+(2*dy).^2)/2; %using central difference
dAs(j)= (w+((t1+t2)/L))*ds(j)*dx; %surface area
Ac(j)=(t(y(j)))*dx; %Cross sectional area
end
  3 件のコメント
Matthew Williams
Matthew Williams 2020 年 12 月 13 日
The codes functionality is solving for heat transfer in a triangular fin at each control volume and each volume has a changing suface area and cross sectional area. At the boundary y=0 the CV of interest is half compared to a centralized control volume, so I have it modeled as j+1/2 as opposed to j+1.
Earlier in the beginning of the code I'm defining the thickness t as a function of y because along the y direction the thickness is changing wrt y, tt is the given thickness at the base of the triangular Fin and L is the given length of the fin from the base to the tip.
t= @(y)(tt/L)*y;
%% Discretization information
M= 41; %number of nodes in the x direction
N= 31; %number of nodes in the y direction
dx=w/(M-1); %spacing between nodes, m
x=[0:dx:w];
dy=L/(N-1); %spacing between nodes, m
y=[0:dy:L];
Walter Roberson
Walter Roberson 2020 年 12 月 13 日
You cannot index at half-integers . You can index a value and divide the result by 2, though.

サインインしてコメントする。

採用された回答

Gouri Chennuru
Gouri Chennuru 2020 年 12 月 16 日
Hi Matthew,
As per my understanding, you are trying to extract the variable "y" with indices (j+1/2) and (j-1/2), from the following lines.
t1=(t(y(j))+t(y(j+1/2)))/2;
t2=(t(y(j-1/2))+t(y(j)))/2;
You cannot point arrays to a particular decimal index.As a workaround make sure that array Index is always a positive integer or a logical value.
Regards,
Gouri Chennuru

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by