From: Awusi Kavuma on
Dear all

I have a data set, X and Y that I want to fit to Gaussian equation Y = A*exp(B*X).
Both Y and X are vectors of same diamension. I need to establish fitting coefficients A and B.
Just as an example: X=[-3, -2.5, -1.5, -1, 0 ,1 ,1.5, 2.5, 3] and
Y=[23 24 25 26 28 26.5 24.5 24 22.8]

Any help please.

Thank you and regards

Kavuma
From: Greg Heath on
On Aug 6, 11:43 am, "Awusi Kavuma" <kavumaw...(a)yahoo.com>
wrote:
> Dear all
>
> I have a data set, X and Y that I want to fit to Gaussian
> equation Y = A*exp(B*X).
> Both Y and X are vectors of same diamension. I need to
> establish fitting coefficients A and B.
> Just as an example:
> X=[-3, -2.5, -1.5, -1, 0 ,1 ,1.5, 2.5, 3] and
> Y=[23 24 25 26 28 26.5 24.5 24 22.8]
>
> Any help please.

1. A*exp(B*X) is not a Gaussian
2. plot(X,Y) indicates you probably meant
Y = A*exp(-B*X.^2)
3. If you didn't care about optimizing a specific
goodness of fit function, and just obtained a
LSE linear fit for log(Y) = log(A) - B*X.^2, I
think you would be dissapointed. Define

W = [log(A) -B]
Then

close all, clear all, clc

X = [-3 -2.5 -1.5 -1 0 1 1.5 2.5 3]
Y = [23 24 25 26 28 26.5 24.5 24 22.8]

% log(Y) = W*[ones(1,length(X));X.^2]

W = log(Y)/[ ones(1,length(X)); X.^2]
%W = [3.2839 -0.017618]
A = exp(W(1)) % 26.68
B = -W(2) % 0.017618

Yhat = A*exp(-B*X.^2);
E = Y-Yhat;
MXAE = max(abs(E)) % 1.32
MAE = mae(Y-Yhat) % 0.45266
RMSE = sqrt(mse(Y-Yhat)) % 0.40731

figure, hold on
plot(X,Y,'o')
plot(X,Yhat,'r')

4. Therefore, you should try MATLAB's nonlinear
curvefitting routines

help curvefit
help lsqcurvefit

Hope this helps.

Greg
From: Greg Heath on
On Aug 6, 3:53 pm, Greg Heath <he...(a)alumni.brown.edu> wrote:
> On Aug 6, 11:43 am, "Awusi Kavuma" <kavumaw...(a)yahoo.com>
> wrote:
>
> > Dear all
>
> > I have a data set, X and Y that I want to fit to Gaussian
> > equation Y = A*exp(B*X).
> > Both Y and X are vectors of same diamension. I need to
> > establish fitting coefficients A and B.
> > Just as an example:
> > X=[-3, -2.5, -1.5, -1, 0 ,1 ,1.5, 2.5, 3] and
> > Y=[23 24 25 26 28 26.5 24.5 24 22.8]
>
> > Any help please.
>
> 1. A*exp(B*X) is not a Gaussian
> 2. plot(X,Y) indicates you probably meant
>    Y = A*exp(-B*X.^2)
> 3. If you didn't care about optimizing a specific
> goodness of fit function, and just obtained a
> LSE linear fit for log(Y) = log(A) - B*X.^2, I
> think you would be dissapointed. Define
>
>      W  = [log(A) -B]
> Then
>
> close all, clear all, clc
>
> X = [-3 -2.5 -1.5  -1   0    1   1.5 2.5    3]
> Y = [23   24   25  26  28 26.5  24.5  24 22.8]
>
> % log(Y)  = W*[ones(1,length(X));X.^2]
>
> W   = log(Y)/[ ones(1,length(X)); X.^2]
> %W       = [3.2839    -0.017618]
> A       = exp(W(1))   % 26.68
> B       = -W(2)       % 0.017618
>
> Yhat    = A*exp(-B*X.^2);
> E       = Y-Yhat;
> MXAE    = max(abs(E))        % 1.32
> MAE     = mae(Y-Yhat)        % 0.45266
> RMSE    = sqrt(mse(Y-Yhat))  % 0.40731
>
> figure, hold on
> plot(X,Y,'o')
> plot(X,Yhat,'r')
>
> 4. Therefore, you should try MATLAB's nonlinear
> curvefitting routines
>
> help curvefit
> help lsqcurvefit

WHOOPS!

I tried them using their defaults and got worse results:

Loglinear Nonlinear
MXAE 1.32 1.2674
MAE 0.45266 0.46553 % Loglinear lower
RMSE 0.40731 0.63722 % Loglinear lower


Good luck on finding a better solution!

Greg