function y=fit(a,x) % function to fit data
y=a(1)*exp(-(x-a(2)).^2/a(3)^2); end;
x = 0:0.5:10 % vector of with data
for i=1:length(x),
y(i)=1.5*exp(-(x(i)-4)^2/2)+rand(1)/5-0.1; end;
e = 0.03 * ones(1, length(x) ) % uncertainties
errorbar(x,y,e,"+") % draw error bars
hold
xi=0:0.2:10
yi=fit([1.4912 3.9911 1.4481],xi)
plot(xi,yi,"g")
plot(x,y,"r*")
xlabel("X-values")
title("Data vs Gaussian")
print("plot1.eps")
Ads help maintain this website.