fitting to a pure cubic and getting residuals
5 views (last 30 days)
Show older comments
Hi. I want to perform a cubic fit (i.e. jsut a term in x^3 with no x^2 or x^1 so cannot use polyfit:
I need to do the fit of my data x and N(:,1). I also need the residuals.
This is my x:
x=[-0.625,-0.5,-0.4,-0.3,-0.2,0,0.2,0.3,0.4,0.5,0.625]'
ft=fittype('a*x^3')
[fitobj,~,~,~]=fit(x,N(:,i),ft)
coeff=fitobj.a
y=N(:,1)
yfit=coeff*x^3
res=y-yfit
0 Comments
Accepted Answer
John D'Errico
on 6 May 2015
Simple is to download polyfitn. But even easier is to just do this:
coeff = (x.^3)\y;
resid = y - coeff*x.^3;
3 Comments
John D'Errico
on 6 May 2015
Yes, what a difference a dot makes. But I meant that you can use polyfitn (a download from the file exchange) to do this. It is hardly worth the effort for such a simple model though, when backslash is so easy to use here.
More Answers (0)
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!