MATLAB Answers

# How to use polyfit instead of fit for fitting an exponential. For GPU processing.

70 views (last 30 days)
Kris Hoffman on 13 Mar 2019
Commented: Walter Roberson on 13 Mar 2019
Ok, I've been fighting this for way too long, and I've posed a similar question to this months ago, but I still do not get the values I so desparately need.
How do I use polyfit to get the 'b' value in the output from fit(X,Y,'exp1')?
I've taken the natural log of every combination of value, used polyval in various ways, and still get nothing within 5 orders of magnitude to what I need. I've read many different answers to this same question in the community, so if you post a link to one, I've probably seen it.
This would be moot if I could use fit with a GPU.
##### 6 CommentsShowHide 5 older comments
Walter Roberson on 13 Mar 2019
If i and j are both scalars, then you only need one squeeze() there instead of 2. You could also use
SS = reshape(SSS(i,j,:), [], 1);

Sign in to comment.

### Answers (1)

Matt J on 13 Mar 2019
Edited: Matt J on 13 Mar 2019
For example,
a=1;
b=2;
x=gpuArray.linspace(0,2,100);
y=a*exp(b*x);
p=polyfit(x,log(y),1);
b_fit=p(1),
produces the desired value,
b_fit =
2
##### 6 CommentsShowHide 5 older comments
Walter Roberson on 13 Mar 2019
polyfit runs on GPU.
If you are requiring 1.5 hours to do the fit() or polyfit then I would worry you would exceed the memory capacity of your GPU.

Sign in to comment.

R2018b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!