MATLAB: Integrand function must return an output vector of the same length as the input vector

quad

Hello
I am trying to run the following code. But I keep getting the following error message, and can't figure out what I am duing wrong.
??? Error using ==> quad at 80 The integrand function must return an output vector of the same length as the input vector.
My code:
t_theta_nul=tid(0.)
function res2=tid(theta_noget)
h=3510;
dx_dtheta=@(theta) 1/2*h*(1-cos(theta));
dy_dtheta=@(theta) -1/2*h*sin(theta);
f1=@(theta) sqrt((dx_dtheta(theta)).^2+(dy_dtheta(theta)).^2);
s=@(theta_noget) quad(f1,theta_noget,pi);
g=9.816;
d=@(theta) 1/2*h*(cos(theta)+1)-(1/2*h*(cos(theta_noget)+1));
f2=@(theta) sqrt(2*g*d);
f3=@(theta) f1./f2;
t=@(theta_noget) quad(@(theta) f3,theta_noget,pi);
res2=t(theta_noget);

Best Answer

You would probably have more success if you used
t=@(theta_noget) quad(@(theta) f3(theta),theta_noget,pi);
After, of course, making other bug fixes such as
f3=@(theta) f1(theta)./f2(theta);
Remember, f1 and f2 and f3 and so on are function handles, so if you name them without passing an argument to them, what you get back is just the function handle.
Even if f1 and so on were full functions instead of function handles, you would be wanting to pass arguments to them, as otherwise you would be invoking them with no arguments.