Searching coefficients of surface polinomial (equivalent to polyfit for surfaces) fixed degree
Show older comments
I'm looking for a the coefficients a1...a6 of the polinomial function
N1 = a1 + a2*x + a3*y + a4*x^2 + a5*x*y + a6*y^2
that goes through the following points. There is no a7, the degree is fixed.
x=[0 1 0 0.5 0.5 0 ]';
y=[0 0 1 0 0.5 0.5]';
z=[1 0 0 0 0 0 ]';
I know there generally is an infinite number of functions, yet the same applies in this case
a=[0 1 0 0.5 0.5 0];
b=[1 2 3 4 5 6];
N2=polyfit(a,b,2);
N2 =
-7.3333 6.0000 3.3333
and MATLAB is able to work with that. I'm looking for something like polyfit for surfaces.
So far I tried:
N1 = scatteredInterpolant(x,y,z,'natural');
The function seems to work fine, but I cannot show the coefficients of the function, also I cannot influence the degree which is required in my case.
xq=0:0.5:1;
yq=0:0.5:1;
N1 = griddata(x,y,z,xq,yq);
It only returns the interpolated surface, not the function coefficients.
Accepted Answer
More Answers (1)
Image Analyst
on 28 Sep 2015
0 votes
If you have the Statistics and Machine Learning Toolbox, I believe fitlm() is the function you want. I think you need more points than 6 though. And I'm not sure what your z variable is used for -- it's not in your model.
1 Comment
Walter Roberson
on 28 Sep 2015
If you treat z as being the N1 value for particular x, y, then you have 6 points and 6 coefficients, and a least-squares does fine.
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!