MATLAB: Trouble using integral function

integral

I am facing errors in integrating the follow ng function.
xtemp=@(lambda)(((h*c)/(lambda*BoltzmnCst*Ts))^2)/(exp(((h*c)/(lambda*BoltzmnCst*Ts)))-1)
xtempintg= integral(xtemp,0,lambdabg)
Everything excep lambda is a constant and defined.
Following is the error I am getting:
Error using /
Matrix dimensions must agree.
Error in My_Code>@(lambda)(((h*c)/(lambda*BoltzmnCst*Ts))^2)/(exp(((h*c)/(lambda*BoltzmnCst*Ts)))-1)
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in My_Code (line 46)
xtempintg= integral(xtemp,0,lambdabg)

Best Answer

First, it will likely be worthwhile to use element-wise operations (‘dot operators’) in appropriate places (here in the division and exponentiation operations):
xtemp=@(lambda)(((h*c)./(lambda*BoltzmnCst*Ts)).^2)./(exp(((h*c)./(lambda*BoltzmnCst*Ts)))-1)
Then add the 'ArrayValued' name-value pair to the integral call:
xtempintg= integral(xtemp,0,lambdabg, 'ArrayValued',1)
When I substituted some random scalars for the other values, that worked correctly.