Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fit power curve with best exponent to data

Subject: fit power curve with best exponent to data

From: JK

Date: 30 Jan, 2013 16:02:07

Message: 1 of 5

Hi,

I'm attempting to fit the following equation to a set of data characterizing something's autocorrelation function:

y=e^(a*x)^n

to determine 'best fit' a and n. An example of the data:

(x):
4.47481932596166
4.47660093553848
4.47838272239611
4.48016468632304
4.48194682710806
4.48372914454029
4.48551163840916
4.48729430850440
4.48907715461608
4.49086017653456
4.49264337405052
4.49442674695494
4.49621029503915
4.49799401809473
4.49977791591363
4.50156198828807
4.50334623501058
4.50513065587403
4.50691525067157
4.50870001919666
4.51048496124308
4.51227007660490
4.51405536507651
4.51584082645259
4.51762646052814
4.51941226709846
4.52119824595914
4.52298439690610
4.52477071973553
4.52655721424396
4.52834388022818
4.53013071748531
4.53191772581277
4.53370490500827
4.53549225486981
4.53727977519571
4.53906746578457
4.54085532643532
4.54264335694714
4.54443155711955
4.54621992675233
4.54800846564559
4.54979717359972
4.55158605041539
4.55337509589359
4.55516430983560
4.55695369204296
4.55874324231756
4.56053296046153
4.56232284627732


(y):
4.47481932596166
4.47660093553848
4.47838272239611
4.48016468632304
4.48194682710806
4.48372914454029
4.48551163840916
4.48729430850440
4.48907715461608
4.49086017653456
4.49264337405052
4.49442674695494
4.49621029503915
4.49799401809473
4.49977791591363
4.50156198828807
4.50334623501058
4.50513065587403
4.50691525067157
4.50870001919666
4.51048496124308
4.51227007660490
4.51405536507651
4.51584082645259
4.51762646052814
4.51941226709846
4.52119824595914
4.52298439690610
4.52477071973553
4.52655721424396
4.52834388022818
4.53013071748531
4.53191772581277
4.53370490500827
4.53549225486981
4.53727977519571
4.53906746578457
4.54085532643532
4.54264335694714
4.54443155711955
4.54621992675233
4.54800846564559
4.54979717359972
4.55158605041539
4.55337509589359
4.55516430983560
4.55695369204296
4.55874324231756
4.56053296046153
4.56232284627732

As far as I can tell, I can't use the curve fitting tool as it won't determine the best fit for exponent n, only a. I have an idea that involves iterating progressively closer solutions to the equation with varying a and n, but haven't yet worked out how to implement it.

Any ideas?

Cheers, JK

Subject: fit power curve with best exponent to data

From: JK

Date: 30 Jan, 2013 16:50:15

Message: 2 of 5

"JK" wrote in message <kebg5v$p8c$1@newscl01ah.mathworks.com>...
> Hi,
>
> I'm attempting to fit the following equation to a set of data characterizing something's autocorrelation function:
>
> y=e^(a*x)^n
>
> to determine 'best fit' a and n. An example of the data:
>
> (x):
> 4.47481932596166
> 4.47660093553848
> 4.47838272239611
> 4.48016468632304
> 4.48194682710806
> 4.48372914454029
> 4.48551163840916
> 4.48729430850440
> 4.48907715461608
> 4.49086017653456
> 4.49264337405052
> 4.49442674695494
> 4.49621029503915
> 4.49799401809473
> 4.49977791591363
> 4.50156198828807
> 4.50334623501058
> 4.50513065587403
> 4.50691525067157
> 4.50870001919666
> 4.51048496124308
> 4.51227007660490
> 4.51405536507651
> 4.51584082645259
> 4.51762646052814
> 4.51941226709846
> 4.52119824595914
> 4.52298439690610
> 4.52477071973553
> 4.52655721424396
> 4.52834388022818
> 4.53013071748531
> 4.53191772581277
> 4.53370490500827
> 4.53549225486981
> 4.53727977519571
> 4.53906746578457
> 4.54085532643532
> 4.54264335694714
> 4.54443155711955
> 4.54621992675233
> 4.54800846564559
> 4.54979717359972
> 4.55158605041539
> 4.55337509589359
> 4.55516430983560
> 4.55695369204296
> 4.55874324231756
> 4.56053296046153
> 4.56232284627732
>
>
> (y):
> 4.47481932596166
> 4.47660093553848
> 4.47838272239611
> 4.48016468632304
> 4.48194682710806
> 4.48372914454029
> 4.48551163840916
> 4.48729430850440
> 4.48907715461608
> 4.49086017653456
> 4.49264337405052
> 4.49442674695494
> 4.49621029503915
> 4.49799401809473
> 4.49977791591363
> 4.50156198828807
> 4.50334623501058
> 4.50513065587403
> 4.50691525067157
> 4.50870001919666
> 4.51048496124308
> 4.51227007660490
> 4.51405536507651
> 4.51584082645259
> 4.51762646052814
> 4.51941226709846
> 4.52119824595914
> 4.52298439690610
> 4.52477071973553
> 4.52655721424396
> 4.52834388022818
> 4.53013071748531
> 4.53191772581277
> 4.53370490500827
> 4.53549225486981
> 4.53727977519571
> 4.53906746578457
> 4.54085532643532
> 4.54264335694714
> 4.54443155711955
> 4.54621992675233
> 4.54800846564559
> 4.54979717359972
> 4.55158605041539
> 4.55337509589359
> 4.55516430983560
> 4.55695369204296
> 4.55874324231756
> 4.56053296046153
> 4.56232284627732
>
> As far as I can tell, I can't use the curve fitting tool as it won't determine the best fit for exponent n, only a. I have an idea that involves iterating progressively closer solutions to the equation with varying a and n, but haven't yet worked out how to implement it.
>
> Any ideas?
>
> Cheers, JK

Sorry y data was supposed to be:
1
0.855523340410541
0.764792429909978
0.678099306458690
0.591926429445276
0.511869260119586
0.440305745138169
0.376841604132816
0.319937411137693
0.269323180085950
0.227400247606494
0.192874818862990
0.165527222064538
0.143002355315252
0.123566543534215
0.106050663207239
0.0913015667970621
0.0788844288733041
0.0690509360482243
0.0622905880650299
0.0573428171801274
0.0529049518861677
0.0482627610391956
0.0432345830290773
0.0372417234342736
0.0328457637930363
0.0276477226422510
0.0234601991511081
0.0182324949704737
0.0134284922961476
0.00925167629657749
0.00606474171412919
0.00491303617287597
0.00435096133409385
0.00441525474186969
0.00469337086290646
0.00552698297526562
0.00584279010748886
0.00550916368456691
0.00517893114313631
0.00512781440834030
0.00542915017028539
0.00557217404356260
0.00547613877038057
0.00621171457529178
0.00635393395783828
0.00612218447936706
0.00559052600160291
0.00592952791009768
0.00589171527465034

Subject: fit power curve with best exponent to data

From: Tom Lane

Date: 30 Jan, 2013 17:09:51

Message: 3 of 5

>> I'm attempting to fit the following equation to a set of data
>> characterizing something's autocorrelation function:
>>
>> y=e^(a*x)^n

Your y seems to drop off exponentially, so you want the exponent to be
negative, and you're raising it to a power that may not be an integer. If I
change your function I can do the following to fit it:

>> myexp = fittype('exp(a*(abs(x-b)^n))')
myexp =
     General model:
     myexp(a,b,n,x) = exp(a*(abs(x-b)^n))
>> fit(x,y,myexp,'start',[-20,4.47,1])
ans =
     General model:
     ans(x) = exp(a*(abs(x-b)^n))
     Coefficients (with 95% confidence bounds):
       a = -103.6 (-115.1, -92.15)
       b = 4.475 (4.474, 4.475)
       n = 1.065 (1.035, 1.094)

While you may not want this function, I hope this illustrates what you can
try with a function that you choose yourself.

-- Tom

Subject: fit power curve with best exponent to data

From: JK

Date: 30 Jan, 2013 19:51:08

Message: 4 of 5

"Tom Lane" <tlane@mathworks.com> wrote in message <kebk50$bq1$1@newscl01ah.mathworks.com>...
> >> I'm attempting to fit the following equation to a set of data
> >> characterizing something's autocorrelation function:
> >>
> >> y=e^(a*x)^n
>
> Your y seems to drop off exponentially, so you want the exponent to be
> negative, and you're raising it to a power that may not be an integer. If I
> change your function I can do the following to fit it:
>
> >> myexp = fittype('exp(a*(abs(x-b)^n))')
> myexp =
> General model:
> myexp(a,b,n,x) = exp(a*(abs(x-b)^n))
> >> fit(x,y,myexp,'start',[-20,4.47,1])
> ans =
> General model:
> ans(x) = exp(a*(abs(x-b)^n))
> Coefficients (with 95% confidence bounds):
> a = -103.6 (-115.1, -92.15)
> b = 4.475 (4.474, 4.475)
> n = 1.065 (1.035, 1.094)
>
> While you may not want this function, I hope this illustrates what you can
> try with a function that you choose yourself.
>
> -- Tom

Hi Tom,

Yeah that's exactly what I was looking for, I'm just having trouble getting one type of model to work: an 'x-exponential' form where f(x) = exp[-(|z|/L)^x]. But thanks for the pointer towards 'fit'.

Jack

Subject: fit power curve with best exponent to data

From: Marc

Date: 1 Feb, 2013 07:00:09

Message: 5 of 5

"JK" wrote in message <kebtjc$kp3$1@newscl01ah.mathworks.com>...
> "Tom Lane" <tlane@mathworks.com> wrote in message <kebk50$bq1$1@newscl01ah.mathworks.com>...
> > >> I'm attempting to fit the following equation to a set of data
> > >> characterizing something's autocorrelation function:
> > >>
> > >> y=e^(a*x)^n
> >
> > Your y seems to drop off exponentially, so you want the exponent to be
> > negative, and you're raising it to a power that may not be an integer. If I
> > change your function I can do the following to fit it:
> >
> > >> myexp = fittype('exp(a*(abs(x-b)^n))')
> > myexp =
> > General model:
> > myexp(a,b,n,x) = exp(a*(abs(x-b)^n))
> > >> fit(x,y,myexp,'start',[-20,4.47,1])
> > ans =
> > General model:
> > ans(x) = exp(a*(abs(x-b)^n))
> > Coefficients (with 95% confidence bounds):
> > a = -103.6 (-115.1, -92.15)
> > b = 4.475 (4.474, 4.475)
> > n = 1.065 (1.035, 1.094)
> >
> > While you may not want this function, I hope this illustrates what you can
> > try with a function that you choose yourself.
> >
> > -- Tom
>
> Hi Tom,
>
> Yeah that's exactly what I was looking for, I'm just having trouble getting one type of model to work: an 'x-exponential' form where f(x) = exp[-(|z|/L)^x]. But thanks for the pointer towards 'fit'.
>
> Jack

Although I think your data is simply silly... CFTOOL worked fine for me for several fits....

Exponential:

General model Exp1:
     f(x) = a*exp(b*x)
Coefficients (with 95% confidence bounds):
       a = 2.545e+157 (-Inf, Inf)
       b = -80.99 (-82.45, -79.54)

Goodness of fit:
  SSE: 0.003883
  R-square: 0.9987
  Adjusted R-square: 0.9987
  RMSE: 0.008994

Gaussian:

General model Gauss1:
     f(x) = a1*exp(-((x-b1)/c1)^2)
Coefficients (with 95% confidence bounds):
       a1 = 978 (-3410, 5366)
       b1 = 4.294 (4.183, 4.405)
       c1 = 0.06875 (0.04881, 0.08869)

Goodness of fit:
  SSE: 0.00313
  R-square: 0.9989
  Adjusted R-square: 0.9989
  RMSE: 0.008161

Just as some examples.... Of course, garbage in, garbage out...

Keep walking, gentleman.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us