MATLAB: Matlab error “Matrix dimensions must agree”

errorfunctionintegralMATLABmatrix

I'm trying to get the integral() of a two functions but I keep getting this error and I don't know why
This is the code for the functions:
R = 0.5; %m
I = 2; %A
u0 = 4*pi*10^-7;
BiotSavart = (u0*R*I)/(4*pi);
max = 50;
px = -R:R/max:R;
py = -R:R/max:R;
pz = 0:R/max:2*R;
fy = @(t) sin(t)./((px-R*cos(t)).^2+(py-R*sin(t)).^2+pz.^2).^(3/2);
fz = @(t) (R-py.*sin(t)-px.*cos(t))./((px-R*cos(t)).^2+(py-R*sin(t)).^2+pz.^2).^(3/2);
By = pz * BiotSavart * integral(fy,0,2*pi);
Bz = BiotSavart * integral(fz,0,2*pi);
I get the error in this line:
fy = @(t) sin(t)./((px-R*cos(t)).^2+(py-R*sin(t)).^2+pz.^2).^(3/2);

Best Answer

Integrating an array, set 'ArrayValued' to 'true':
By = pz .* BiotSavart .* integral(fy,0,2*pi, 'ArrayValued',1);
Bz = BiotSavart * integral(fz,0,2*pi, 'ArrayValued',1);
That runs without error.