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 .
Jommy
source share