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)

 Réponse acceptée

Star Strider
Star Strider le 12 Fév 2021

0 votes

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.

2 commentaires

Zhaque
Zhaque le 12 Fév 2021
Simply adding the . worked
Star Strider
Star Strider le 12 Fév 2021
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by