Show how to fit data using a Gaussian function
Code: "fit_plot.m". Programming language: Octave DMelt Version 1.4. Last modified: 11/14/1970. License: Pro
https://datamelt.org/code/cache/fit_plot_5822.m
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


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.