Data Fitting and Optimization

*****************************************************
** Fitting artificially generated data
****** The System ***********************************
spectrometer(MHz)  *
spinning_freq(kHz) *
channels           C13
nuclei             C13
atomic_coords      *
cs_isotropic       *
csa_parameters     *
j_coupling         *
quadrupole         *
dip_switchboard    *
csa_switchboard    *
exchange_nuclei    *
bond_len_nuclei    *
bond_ang_nuclei    *
tors_ang_nuclei    *
groups_nuclei      *
******* Pulse Sequence ******************************
CHN 1
timing(usec)       (1000)60
power(kHz)          0
phase(deg)          0
freq_offs(kHz)      0
******* Variables ***********************************

** This section was used to generate the "data"
*err=0.04*(rand(60,1)-0.5)
** err is uniformly distributed from -0.02 to 0.02
*A=1
*k=0.1
*signal_re=A*(1-exp(-k*t_1))+err
******************************************************

** Data fitting section
A=2
k=0.4
signal_re=A*(1-exp(-k*t_1))
fit_par A k

******* Options **********
rho0               I1z
observables        I1z
EulerAngles        *
n_gamma            *
line_broaden(Hz)   *
zerofill           *
FFT_dimensions     *
options            -am -l0 -re -confint

***********************************
** Finding minimum of a function **
****** The System *****************
spectrometer(MHz)  *
spinning_freq(kHz) *
channels           C13
nuclei             C13
atomic_coords      *
cs_isotropic       *
csa_parameters     *
j_coupling         *
quadrupole         *
dip_switchboard    *
csa_switchboard    *
exchange_nuclei    *
bond_len_nuclei    *
bond_ang_nuclei    *
tors_ang_nuclei    *
groups_nuclei      *
******* Pulse Sequence ******************************
CHN 1
timing(usec)       0
power(kHz)         0
phase(deg)         0
freq_offs(kHz)     0
******* Variables ***********************************
penalty sqrt((x-1)^2+(y+10)^2)
fit_par x y
******* Options **********
rho0               I1z
observables        I1z
EulerAngles        *
n_gamma            *
line_broaden(Hz)   *
zerofill           *
FFT_dimensions     *
options            -po -am

********************************************************************
** Solving linear system of equations A*x=b using least squares   **
****** The System **************************************************
spectrometer(MHz)  *
spinning_freq(kHz) *
channels           C13
nuclei             C13
atomic_coords      *
cs_isotropic       *
csa_parameters     *
j_coupling         *
quadrupole         *
dip_switchboard    *
csa_switchboard    *
exchange_nuclei    *
bond_len_nuclei    *
bond_ang_nuclei    *
tors_ang_nuclei    *
groups_nuclei      *
******* Pulse Sequence ******************************
CHN 1
timing(usec)      (0)2
power(kHz)         0
phase(deg)         0
freq_offs(kHz)     0
******* Variables ***********************************************
A=["1 2; 3 5"]
b=["1; 2"]
x=["0; 0"]
fit_re=["0; 0"]
signal_1_re=A*x-b
fit_par x([1:2])
******* Options **********
rho0               I1z
observables        I1z
EulerAngles        *
n_gamma            *
line_broaden(Hz)   *
zerofill           *
FFT_dimensions     *
options            -am -x0 -re