matlab fminsearch curve fitting HELP!!
I’m very new to Matlab and working on a code based on planck’s body radiation plots.
I’m trying to use fminsearch to estimate temperature from a set of three wavelength(x) and irradiance(y) data points. Temperature is the only parameter to be estimated, others are either xy data or constants.
My code is as follows:
c=2.997*10.^8; % m/s (speed of light)
h=6.6261*10.^-34; % J.s (planck’s constant)
k=1.38*10.^-23; % T/K (boltzmann’s constant)
xdata=[5.006e-07 5.104e-07 5.192e-07];
ydata=[3.223e+12 3.424e+12 3.606e+12];
figure(1)
clf
h1=plot(xdata,ydata,’ko’,’MarkerFaceColor’,’k’);
set(gca,’YLim’,[0,0.5*10^13]);
set(gca,’XLim’,[0.3*10^-6,0.7*10^-6]);
set(gca,’XTick’,xdata)
xlabel(‘Wavelength (m)’);
ylabel(‘Energy Density’);
t=3000;
pred = @(x,T) (c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1));
hold on
h2=plot(xdata,pred,’r-‘);
err = @(x,T) sum((((c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1))-ydata).^2);
T = fminsearch(@(x) err(xdata,x(1)),[3000]);
Please let me know where I’m wrong as I can’t figure it out.
Thanks.I’m very new to Matlab and working on a code based on planck’s body radiation plots.
I’m trying to use fminsearch to estimate temperature from a set of three wavelength(x) and irradiance(y) data points. Temperature is the only parameter to be estimated, others are either xy data or constants.
My code is as follows:
c=2.997*10.^8; % m/s (speed of light)
h=6.6261*10.^-34; % J.s (planck’s constant)
k=1.38*10.^-23; % T/K (boltzmann’s constant)
xdata=[5.006e-07 5.104e-07 5.192e-07];
ydata=[3.223e+12 3.424e+12 3.606e+12];
figure(1)
clf
h1=plot(xdata,ydata,’ko’,’MarkerFaceColor’,’k’);
set(gca,’YLim’,[0,0.5*10^13]);
set(gca,’XLim’,[0.3*10^-6,0.7*10^-6]);
set(gca,’XTick’,xdata)
xlabel(‘Wavelength (m)’);
ylabel(‘Energy Density’);
t=3000;
pred = @(x,T) (c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1));
hold on
h2=plot(xdata,pred,’r-‘);
err = @(x,T) sum((((c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1))-ydata).^2);
T = fminsearch(@(x) err(xdata,x(1)),[3000]);
Please let me know where I’m wrong as I can’t figure it out.
Thanks. I’m very new to Matlab and working on a code based on planck’s body radiation plots.
I’m trying to use fminsearch to estimate temperature from a set of three wavelength(x) and irradiance(y) data points. Temperature is the only parameter to be estimated, others are either xy data or constants.
My code is as follows:
c=2.997*10.^8; % m/s (speed of light)
h=6.6261*10.^-34; % J.s (planck’s constant)
k=1.38*10.^-23; % T/K (boltzmann’s constant)
xdata=[5.006e-07 5.104e-07 5.192e-07];
ydata=[3.223e+12 3.424e+12 3.606e+12];
figure(1)
clf
h1=plot(xdata,ydata,’ko’,’MarkerFaceColor’,’k’);
set(gca,’YLim’,[0,0.5*10^13]);
set(gca,’XLim’,[0.3*10^-6,0.7*10^-6]);
set(gca,’XTick’,xdata)
xlabel(‘Wavelength (m)’);
ylabel(‘Energy Density’);
t=3000;
pred = @(x,T) (c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1));
hold on
h2=plot(xdata,pred,’r-‘);
err = @(x,T) sum((((c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1))-ydata).^2);
T = fminsearch(@(x) err(xdata,x(1)),[3000]);
Please let me know where I’m wrong as I can’t figure it out.
Thanks. fminsearch, blackbody, fit, curve fitting MATLAB Answers — New Questions