Help with code to fit a BlackBody to data to find temperature
Afficher commentaires plus anciens
Hello,
I am looking to fit a blackbody curve to some data I have and determine the temperature. I'm getting stuck as I am getting an error saying I have too many input arguments. I think this is about line 23? But I'm struggling to correct it.
Here's what I have so far:
%fit BlackBody to data
%constants needed for BB equation
c=2.997*10.^8;
h=6.6261*10.^-34;
k=1.38*10.^-23;
%wavelgnths and flux densities
w = [0.000000445,0.000000477,0.00000163,7.625*10^-7,0.000000806,0.00000122,0.00000215,6.231*10^-7,0.000000658,3.543*10^-7,0.000000365,4.392*10^-7,0.000000231,3.465*10^-7,5.468*10^-7,0.000000291,0.000000212,0.000000551,9.134*10^-7];
f = [1.03919*10^-27,1.05624*10^-27,6.5907*10^-28,8.72017*10^-28,8.54111*10^-28,7.23846*10^-28,5.81202*10^-28,1.00213*10^-27,9.66438*10^-28,1.13496*10^-27,1.12742*10^-27,1.04994*10^-27,1.2677*10^-27,1.18296*10^-27,1.03105*10^-27,1.3626*10^-27,1.31748*10^-27,1.06062*10^-27,8.11377*10^-28];
%plot figure with data
figure
plot(w, f, 'o', 'MarkerFaceColor', 'b', 'MarkerSize', 5);
xlabel('Wavelength (m)');
ylabel('Flux Density (W/m^2/Hz)');
%BlackBody function
T = 30000; %starting point for Temperature
BB = @(lam,T) 2.*h.*(c.^2)./((lam.^5).*1./(exp((h.*c)./(lam.*k.*T))-1));
%get difference between BB and data, and find minimum
diff = @(T) sum((BB(w,T)-f).^2);
T = fminsearch(diff,T);
%add fit to plot with red line
hold on
plot(w,diff(w,T),'r-');
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

