MATLAB: What is wrong with the code? it returns the error “In an assignment A(:) = B, the number of elements in A and B must be the same.”

differential equationseuler method

Hello, I have written this code and I do not understand why it keeps resulting in the same error message, "In an assignment A(:) = B, the number of elements in A and B must be the same.". Can anyone tell me how to go about correcting this error?
ac=7.854*10^-7 %cross sectional area
k=110; % Conductive heat transfer coefficient
ta=25; % Room temperature
h=20; %Convective heat transfer coefficient
p=0.04063; %Perimeter of cylinder
s=0.002; %step size
xfinal=0.02; % final distance
N=xfinal/s;
x(1)=0;
t(1)=50;
z(1)=0;
for i=1:N
x(i+1)=x(i)+s;
t(i+1)=t(i)+s*(z(i));
z(i+1)=z(i)+s*(h*p/k*ac)*(t-ta(i));
end

Best Answer

You have defined β€˜ta’ as a scalar, and since it never changes, there is no reason to subscript it.
Change the β€˜z’ assignment in the loop to:
z(i+1)=z(i)+s*(h*p/k*ac)*(t(i)-ta);
to solve the problem.