• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

calculating specific exponential fit

toughwimp11

Senior member
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
 
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

 
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.
 
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. 😛
 
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. 😛

So am I... by proxy, but that's no excuse to let yourself get soft.
 
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. 😛

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

You're sick.
 
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.
 
Back
Top