0

I have a kind of data and want to find the equation(poly coeff) of given data. For example equation for given sample data 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 forpolfitbut It only works for one variable.

Horizon
  • 75
  • 3
  • 11

3 Answers3

0

polyfitn should help...

Another approach: In the general case of non-linear data fitting you can easily use lsqnonlin.

matheburg
  • 2,097
  • 1
  • 19
  • 46
0

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

Dusty Campbell
  • 3,146
  • 31
  • 34
0

As Dusty Campbell pointed out you can use the fit function. To do this you have to build a mesh 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 with 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'll see the solver converges to the correct solution p1 = 1, p2 = 10.

Community
  • 1
  • 1
Jommy
  • 1,020
  • 1
  • 7
  • 14