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 vue (au cours des 30 derniers jours)
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 commentaires
Matthew Williams
Matthew Williams le 13 Déc 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];
Walter Roberson
Walter Roberson le 13 Déc 2020
You cannot index at half-integers . You can index a value and divide the result by 2, though.

Connectez-vous pour commenter.

Réponse acceptée

Gouri Chennuru
Gouri Chennuru le 16 Déc 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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by