calculating specific exponential fit

toughwimp11

Senior member
May 8, 2005
415
0
76
So I'm trying to find the method of calculating the exponential fit y=A*exp(x/-B)+C for a data set (x,y). I'm trying to program this into matlab and i have no idea how i would go about it. any help is appreciated.

edit: if this doesn't belong here, please move it
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
Something like the following should do the trick:


A=1;
B=1;
C=1;
params0=[A,B,C];%arrange the parameters for the optimization routine

data=[x,y];%read in using dlmread if necessary
[params,SSR]=fminunc(@(params) ExpFit(params,data),params0);%fits the function using a Quasi-Newton method (could use fminsearch instead)

%%%%%%%%%%%%%%%%%%%%%%%%%
function [SSR,results]=ExpFit(params,data)
%Function that fits the exponential

yhat=params(1).*exp(data:),1)./-params(2))+params(3);%model values
SSR=sum((yhat-data:),2).^2));%sum of square of residuals

 

Born2bwire

Diamond Member
Oct 28, 2005
9,840
6
71
Originally posted by: CycloWizard
Something like the following should do the trick:

display('Start.');
%Phi is the over which you are taking your contour integration.
phi = 0.0; A=0.5*pi*atan2(1.0,0.0; B=A+1; C=0.1*B;
Ill=[A,B-1.0,(C-.1)*1.0e1];%arrange visual aesthetics
[X,Y] = pol2cart(Rho, Phi); d=[X,Y];
[Il,stuff]=fminunc(@(Il) ExpFit(Il,d),Ill);%fits the function using a Quasi-Gaussian method (could use fmaxsearch instead)
function [stuff,morestuff]=ExpFit(Il,d)
%Function that fits the polynomial
%values
ythat=Il(1).*exp(d:),1)./-Il(2))+Il(3)*exp(-0.5*i*phi);
%sum
stuff=sum((ythat-d:),2).^2));
display('Done.');


Bah, no self respecting engineer would write that kind of code. Remember the first rule to coding and job security: Lie in your comments.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
Originally posted by: Born2bwire
Bah, no self respecting engineer would write that kind of code. Remember the first rule to coding and job security: Lie in your comments.
Meh. I'm a government employee now, so I have plenty of job security. :p
 

Born2bwire

Diamond Member
Oct 28, 2005
9,840
6
71
Originally posted by: CycloWizard
Originally posted by: Born2bwire
Bah, no self respecting engineer would write that kind of code. Remember the first rule to coding and job security: Lie in your comments.
Meh. I'm a government employee now, so I have plenty of job security. :p

So am I... by proxy, but that's no excuse to let yourself get soft.
 

bobsmith1492

Diamond Member
Feb 21, 2004
3,875
3
81
Originally posted by: Born2bwire
Originally posted by: CycloWizard
Originally posted by: Born2bwire
Bah, no self respecting engineer would write that kind of code. Remember the first rule to coding and job security: Lie in your comments.
Meh. I'm a government employee now, so I have plenty of job security. :p

So am I... by proxy, but that's no excuse to let yourself get soft.

You're sick.
 

blahblah99

Platinum Member
Oct 10, 2000
2,689
0
0
Originally posted by: toughwimp11
So I'm trying to find the method of calculating the exponential fit y=A*exp(x/-B)+C for a data set (x,y). I'm trying to program this into matlab and i have no idea how i would go about it. any help is appreciated.

edit: if this doesn't belong here, please move it

x = [ a1 a2 a3 a4 ... an]
y = [ b1 b2 b3 b4 ... bn]

Where a and b are coefficients...

P = polyfit(x,y,N) where N is the order of the polynomial, less than elements in x and y.

P contains the coefficients of the polynomial fitted to the data set.

Finally, use polyval to evaulate a test data set.