MATLAB: “Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 51-by-1” appears from A(N-1, N-2) = aw; How to solve this? Not sure what it says… Maybe someone can help me

pulsatile flow in a pipe

%Data Given
N = 51;
mu = 0.1; %Pa
dt = 0.01; %delta time
dr = 0.0002; %radius between the points
rho = 1000; %kg/m3
k = [0,0.1,0.25,0.5,0.85]; %time
R = 0.01; %m
[r] = d_gridpoint(R);
%Constant Break Down
q = (mu*dt)/(rho*dr^2);
p = (mu*dt)./(2*rho*r*dr);
e = (2*mu*dt)/(rho*dr^2);
aw = (q)-(p);
ap = (-(e)-1);
ae = (q)+(p);
%Replace the Constant Into General Equation
%Apply Boundary Condition To Form a Matrix
%Initialization
A=zeros(N-1);
for i=2:N-2
A(i,i)=ap;
A(i,i-1)=aw(i);
A(i,i+1)=ae(i);
end
%Neumann Boundary Condition
A(1,1)=ap;
A(1,2)=(2*mu*dt)./(rho*dr.^2);
%Dirichlet Boundary Condition
A(N-1,N-1)=ap;
A(N-1,N-2)=aw;

Best Answer

We can tell from the line A(i,i-1)=aw(i); that aw is a vector of length at least N-2 . But in the line A(N-1,N-2)=aw you are attempting to assign that vector into the single location A(N-1,N-2)