Error using integral function with anonymous function
I am trying to use the following code to calculate the values of F(i,j) which is the integral of the anonymous function that I parameterized as a function of T and lambda. I believe I vectorized it correclty. However, the error I get says that the array has incompatible sizes, which I don’t understand because the same size of array worked fine for another section of the code.
“`C1 = 3.742e8;
C2 = 1.4388e4;
SB = 1.38*10.^-23; %Boltzmann’s constant
C1 = 3.742*10^8; % First constant W-micron^4/m^2
C2 = 1.4388*10^4; %Second constant microns-K
T = [300,500,1000,2000,3000,5800]; %Temperature in Kelvins
lambda = 0.1:0.1:30;%wavelength in microns
lengthT = length(T);
length_L = length(lambda);
E = zeros(lengthT,length_L);
E_prime = zeros(lengthT,length_L);
F = zeros(lengthT,length_L);“`
“`for i = 1:lengthT
for j = 1:length_L
fun = @(T, lambda) C1./(SB.*T.^4*(lambda.^5.*(exp(C2/(lambda.*T))-1)));
F(i,j) = integral(fun(T,lambda),0,length_L);
end
end“`I am trying to use the following code to calculate the values of F(i,j) which is the integral of the anonymous function that I parameterized as a function of T and lambda. I believe I vectorized it correclty. However, the error I get says that the array has incompatible sizes, which I don’t understand because the same size of array worked fine for another section of the code.
“`C1 = 3.742e8;
C2 = 1.4388e4;
SB = 1.38*10.^-23; %Boltzmann’s constant
C1 = 3.742*10^8; % First constant W-micron^4/m^2
C2 = 1.4388*10^4; %Second constant microns-K
T = [300,500,1000,2000,3000,5800]; %Temperature in Kelvins
lambda = 0.1:0.1:30;%wavelength in microns
lengthT = length(T);
length_L = length(lambda);
E = zeros(lengthT,length_L);
E_prime = zeros(lengthT,length_L);
F = zeros(lengthT,length_L);“`
“`for i = 1:lengthT
for j = 1:length_L
fun = @(T, lambda) C1./(SB.*T.^4*(lambda.^5.*(exp(C2/(lambda.*T))-1)));
F(i,j) = integral(fun(T,lambda),0,length_L);
end
end“` I am trying to use the following code to calculate the values of F(i,j) which is the integral of the anonymous function that I parameterized as a function of T and lambda. I believe I vectorized it correclty. However, the error I get says that the array has incompatible sizes, which I don’t understand because the same size of array worked fine for another section of the code.
“`C1 = 3.742e8;
C2 = 1.4388e4;
SB = 1.38*10.^-23; %Boltzmann’s constant
C1 = 3.742*10^8; % First constant W-micron^4/m^2
C2 = 1.4388*10^4; %Second constant microns-K
T = [300,500,1000,2000,3000,5800]; %Temperature in Kelvins
lambda = 0.1:0.1:30;%wavelength in microns
lengthT = length(T);
length_L = length(lambda);
E = zeros(lengthT,length_L);
E_prime = zeros(lengthT,length_L);
F = zeros(lengthT,length_L);“`
“`for i = 1:lengthT
for j = 1:length_L
fun = @(T, lambda) C1./(SB.*T.^4*(lambda.^5.*(exp(C2/(lambda.*T))-1)));
F(i,j) = integral(fun(T,lambda),0,length_L);
end
end“` anonymous, function, parameterize, vectorize, integral, integration, error MATLAB Answers — New Questions