Polyfit generates Nan coefficients

Hi, I'm trying to determine a third degree polynomial fit from my excel data. I have done this before and there's been no problem (although I've only used polyfit up to a degree of 2) but for some reason a, b, c and d (the coefficients of the third degree polynomial return as NaN?! I've done this on excel and I know they're quite low (a=10^-24) but this should still work right?! Also d should be 291.05 so in that case d should at least show, which it doesn't... Someone please help!
clc clear
filename='216 distal testing.xlsx'
stretch=xlsread(filename,1,'Q:Q')
truestress=xlsread(filename,1,'S:S')
p1=polyfit(truestress,stretch,3); stretchinvfit=p1(1)*truestress.^3+p1(2)*truestress.^2+p1(3)*truestress+p1(4);
a=p1(1)
b=p1(2)
c=p1(3)
d=p1(4)

Risposte (2)

Matt J
Matt J il 16 Gen 2015

0 voti

If it worked before on different data, then the data you have now is bad...

2 Commenti

Jenny
Jenny il 16 Gen 2015
Modificato: Jenny il 16 Gen 2015
How can it be "bad" data? I tried it with another set of data and it doesn't work then either! Does matlab have a max. number of data points it can deal with? I do have quite a few (410 set).
Matt J
Matt J il 16 Gen 2015
Modificato: Matt J il 16 Gen 2015
Why not attach the offending truestress, stretch data in a .mat file so that we can try it ourselves?
Incidentally, the better way to calculate the fitted points is with polyval
stretchinvfit=polyval(p1,truestress);

Accedi per commentare.

John D'Errico
John D'Errico il 16 Gen 2015

0 voti

There is a good chance that your model is having a problem. With a coefficient as small as 1e-24, you are verging into numerical nightmares. The linear algebra will probably be having a difficult time estimating coefficients with a huge dynamic range. 25 powers of 10 or so is just too much for MATLAB to handle.
FAR better is to scale your data, but to help you more, we would really need to see some data.
410 points is nothing.

Categorie

Richiesto:

il 16 Gen 2015

Risposto:

il 16 Gen 2015

Community Treasure Hunt

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

Start Hunting!

Translated by