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 visualizzazione (ultimi 30 giorni)
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 Commenti
Matthew Williams
Matthew Williams il 13 Dic 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];

Accedi per commentare.

Risposta accettata

Gouri Chennuru
Gouri Chennuru il 16 Dic 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

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by