integral2() assumes that the function handle is able to accept matrix inputs. However, the fun() function in your code does not work correctly with matrix inputs. The following codes shows a quick fix using arrayfun
light_dir = [-0.6626;0;-0.7490];
camera_dir = [-1;0;0];
R = sqrt(2/(4*pi));
x_c =@(theta,phi) R.*sin(theta).*cos(phi);
y_c =@(theta,phi) R.*sin(theta).*sin(phi);
z_c =@(theta) R.*cos(theta);
normal =@(theta,phi) [x_c(theta,phi); y_c(theta,phi); z_c(theta)];
fun = @(theta,phi) (dot(light_dir,normal(theta,phi))).*(dot(camera_dir,normal(theta,phi))<0).*R^2.*sin(theta);
intensity = integral2(@(THETA, PHI) arrayfun(@(theta,phi) fun(theta, phi), THETA, PHI) ,0,pi,0,2*pi);
Best Answer