How can I get my x-and y-values of my polynomial fit into a matrix?

Hi, I have made a polynomial fit to my data from the laboratory, but can't find out how to get this polynomial fit into a matrix for further use and extraction into Excel. I can easily plot it, but thats is strait from the fit-function as seen in my script:
RowTid14 = 4385; %Chosen timevalue at start of last cycle 4385
RowX14 = RowTid14;
RowY14 = RowX14;
T14y=csvread('Test14.txt', RowY14, 1);
T14x=csvread('Test14.txt', RowX14, 2);
T14tid=csvread('Test14.txt', RowTid14, 0);
enomtest14=T14x(:,1)/z6;
%Data
x = 0.05+log(1+enomtest14);
y = (T14y(:,1)/Az6).*(1+enomtest14);
%Polynomial fit of my data
Fit14 = fit(x,y,'poly9');
%Plot of my data and my fit
plot(Fit14)
hold on
plot(x,y)
xlabel('True Strain','Fontsize',10)
ylabel('True Stress [N/mm^2]','Fontsize',10)
set(gca,'XDir','reverse')
set(gca,'YDir','reverse')
xlim([-0.52 0])
ylim([-7 0.1])
legend('Fit','Data','location','North')
So what i would like, is help to get the x- and y-values for the red line into a matrix [1020x2].
Thanks in advance for all answers.
-Stian

1 Comment

And here is the polynomial function, if it is needed:
Linear model Poly9:
Fit14(x) = p1*x^9 + p2*x^8 + p3*x^7 + p4*x^6 +
p5*x^5 + p6*x^4 + p7*x^3 + p8*x^2 + p9*x + p10
Coefficients (with 95% confidence bounds):
p1 = 6.475e+05 (-8.204e+05, 2.115e+06)
p2 = 1.286e+06 (-1.674e+06, 4.247e+06)
p3 = 1.044e+06 (-1.389e+06, 3.477e+06)
p4 = 4.387e+05 (-6.032e+05, 1.481e+06)
p5 = 9.773e+04 (-1.478e+05, 3.433e+05)
p6 = 9523 (-2.093e+04, 3.998e+04)
p7 = -173.7 (-1854, 1507)
p8 = -95.25 (-172.1, -18.43)
p9 = 3.246 (-1.413, 7.905)
p10 = 0.004628 (-0.1033, 0.1125)

Sign in to comment.

Answers (2)

The bigger problem is the choice of a fitting polynomial of order 9 is giving (mostly) nonsense.
Just as an example, look at the p6 and p7 terms--
>> p6 = 9523; e6=[-2.093e+04, 3.998e+04];
>> p7 = -173.7; e7=[-1854, 1507];
>> [p6-e6]/p6*100 % per cent est error in coefficient
ans =
319.78 -319.83
>> [p7-e7]/p7*100
ans =
-967.36 967.59
>>
That's 300% and 1000% error estimated; the value of the coefficients is worthless.
Have you plotted the data itself FIRST; surely there's some better model that has some physical basis, no matter how removed. If it's simply for interpolation or correlation, use a smoothing spline or the like.
Anyway, that problem aside, the methods for a fit object are documented under the heading of Fit Postprocessing but you've got more work to do before you're ready for them.

5 Comments

Thank you for your comments, dpb.
To be honest, I disagreee. This is because the fitting to the graph is good (as I see for my problem). Can it be that the fitting prosedure of a cyclic test is the reason why this p6 and p7 isnt good? This test is a compression of rubber, where the data on the Y-axis is rising when the specimen is being compressed, and then going back down after the compression. And because it is rubber, the graph will not go the same way back down, but a way that is lower than the way up to max compression. This might be the reason for the "error"-estimate? If it was a single line, I could agree that it might look very bad with those error-calculations.
My point in this fitting, is to find the "middle" of the loading-unloading curve, and the estimated fit I have found, is good when looking at the visuals representation.
I tried to use a lower polynomial, and the fitting just got off the wanted fit as poly9 shows.
%Polynomial fit of my data
Fit14 = fit(x,y,'poly9');
Fit15 = fit(x,y,'poly5')
Fit16 = fit(x,y,'poly3')
%Plot of my data and my fit
plot(Fit14,'r')
hold on
plot(Fit15,'black')
hold on
plot(Fit16,'g')
hold on
plot(x,y)
xlabel('True Strain','Fontsize',10)
ylabel('True Stress [N/mm^2]','Fontsize',10)
set(gca,'XDir','reverse')
set(gca,'YDir','reverse')
xlim([-0.52 0])
ylim([-7 0.1])
legend('Fit1: polynomial 9','Fit2: polynomial 5','Fit3: polynomial 3','Data','location','North')
Do you agree that it is a good fit for my problem now?
I might accept the 5th order but I pretty much stand by the comment on a 9th-order poly. Would have to see the raw data and results to really comment in depth.
I'd still think a spline would likely do the same job with less of such issues if there isn't any analytic model on which to base the correlation.
I added the rawdata in this text-document. There are 3 columns: 1st is the time [s] used on the test, the 2nd is the force [N] and the 3rd is the compression measured in mm [mm].
This data will be used to modify a material model (hyperelastic rubber models like Arruda Boyes, Ogdens, Neo-Hooke etc. if you are familiar with them). The data from the lab (text-document) isnt that bad, but since the hyperelastic models are hyperelastic, they dont take softening in account. The models will only produce a single line where the loading and unloading will go the exact same route (if friction is set to 0). So I have to use a fit in between these raw data (text-document) to represent that single loading/unloading route.
Looking forward to more replys.
BTW, Az6=53.47265 and z6=7.10
But back to the original question: Do you know how I can get those x- and y-values from that fit-curve into a matrix 1020 rows 2 columns?

Sign in to comment.

...how I can get those x- and y-values from that fit-curve into a matrix 1020 rows 2 columns
You've already got x and y; if you want an array just concatenate them (but note that you may not actually need to create another explicit array depending on your end objective).
xy=[x y];
I thought you were speaking of evaluating the fit or some other result which is in the methods for the fit object documented under "postprocessing".
To finish up our previous discussion, I did look at the fit and run your script last night but got too enamored by the rain event here to get back (we're in D4 "Exceptional" drought conditions and are in our third year so anything that aids that is really big news at the moment). Anyway, iff the only purpose of the fit were to evaluate the poly between the two end conditions, I'd agree you can get by w/ either but if it were me I'd go with the 5th instead of 9th just on the principle of parsimony.

Categories

Asked:

on 8 Jun 2014

Answered:

dpb
on 9 Jun 2014

Community Treasure Hunt

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

Start Hunting!