Syntax for numerically integrating an anonymous function on one of its variables
Show older comments
I'm a Matlab newbie and am struggling to get the right syntax for numerically integrating a simple anonymous function on one of its variables. The M_e function (Planck's law) below is supposed to set up x (the wavelength) as the variable of interest, while the values of other parameters (h, c, k, T) are provided in earlier lines. M_e_int should integrate this function between two user-input wavelengths (lambda1, lambda2). However, I'm getting an unspecified error on the M_e_int line.
What am I doing wrong? Do I need to define x as a scalar somehow?
M_e = @(x) (2. * pi * h * c.^2) / (x.^5 * (exp((h * c)/(x * k * T)) - 1));
M_e_int = integral(M_e,lambda1,lambda2)
Accepted Answer
More Answers (1)
YT
on 6 Sep 2018
You're missing some dots in your expression. Dots stand for element-wise multiplication when using arrays/matrices, so you need them when your doing calculations with 'x'
M_e = @(x) (2 * pi * h * c^2)./(x.^5.*(exp((h * c)./(x * k * T)) - 1));
M_e_int = integral(M_e,lambda1,lambda2)
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!