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 view (last 30 days)
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 Comments
Matthew Williams
Matthew Williams on 13 Dec 2020
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];

Sign in to comment.

Accepted Answer

Gouri Chennuru
Gouri Chennuru on 16 Dec 2020
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

More Answers (0)

Categories

Find more on Matrices and Arrays 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!