MATLAB: How to fit custom polynomial equation

curve fittingMATLAB

Following is the poly32 model,
equation(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p30*x^3 +
p21*x^2*y + p12*x*y^2
In the above equation i dont want p12*x*y^2 during my curve fitting(i.e. p12 should be zero). How can i achieve it?

Best Answer

You could download polyfitn from the file exchange.
But if you already know how to use the curve fitting toolbox, then just specify a custom equation of the desired form. Something like this:
modelform = fittype('p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p30*x^3 + p21*x^2*y',...
'coeff',{'p00','p10','p01','p20','p11','p02','p30','p21'},...
'indep',{'x','y'},'depend','z');
It will be treated as a nonlinear model internally as a function of the parameters, but since all of the coefficients actually do enter linearly, they will be easy to fit. fit should have no problems.