Polyphyte for two variables

I have some kind of data and you want to find the equation (poly coeff) of the data. For example, the equation for the data for this sample is simple a^2*b+10

 a\b 5 10 15 ________________________ 3| 55 100 145 4| 90 170 250 5| 135 260 385 6| 190 370 550 

I checked polfit , but it only works for one variable.

0
matlab data-fitting
source share
3 answers

As Dusty Campbell pointed out, you can use the fit function. To do this, you need to build a grid with your data

 a = [3 4 5 6]; b = [5 10 15]; [A, B] = meshgrid(a, b); C = (A.^2).*B + 10; 

and then call fit using a custom equation

 ft = fittype('p1*a^2*b + p2', 'independent',{'a','b'}, 'dependent','c'); opts = fitoptions('Method','NonlinearLeastSquares', 'StartPoint',[0.5,1]); [fitresult, gof] = fit([A(:), B(:)], C(:), ft, opts); 

As you will see, the solver converges to the correct solution p1 = 1 , p2 = 10 .

0
source share

polyfitn should help ...

Another approach: in general, when installing non-linear data, you can easily use lsqnonlin .

0
source share

Looks like you need the fit function from Curve Fitting Tools . Or perhaps polyfitn created and shared by another Matlab user.

0
source share

All Articles