MATLAB: How to store output of looping integral in an array

integralloopMATLAB C/C++ Math Librarymatrix

Hi, I am trying to store the store the output of the inetgral of fun2 in a matrix ni. From my code, I just get the same repeating values in the matrix. Any help is appreciated.
for T1 = 173:1:1273 %loop for different temperatures
fun2 = @(E) (1.0/(2*pi^2*h^3)*(2*m)^(3/2)*sqrt(E-Ec)).*(1.0 ./(1+exp((E-Ef)/(k*T1))));
n2 = integral(fun, Ec, Ec+(.3/(6.242*10^18)));
ni(T1-172,:) = [T1,n2]; %store in matrix "ni"
end

Best Answer

I'm guessing you have some kind of units issue, such that something you are calculating is many orders of magnitude out of whack, or that you have something wrong in your formula.
You didn't tell us what all of those constants are (e.g. k), so I just set them all to 1, just to see if I could get your code to work at all.
I got what you did ... all the values the same. But I noticed that you are integrating over a tiny interval of something around 10^-18. So, it's not too surprising that your functions are all effectively equal over that tiny range, and give the same result.
When I integrate over [Ec, Ec+5000], I see variation in the output.
So, I would just carefully check all your units and the formula itself.