1

I need some help working with multi-dimentional polynomials. Amost everyhting I find is 1-D.

Let's say that I have the data

z = [200, 250, 190, 180, 220]
x = [100,101, 98, 92, 120]
y = [5, 10, 15,22,8]

where Z will be my dependent and X and Y are my dependent variables (let's call it x and y).

I want to fit a 2-D polynomial of the type

   f(x,y) = a + b*x + c*x**2 + d*y + e*y**2 + g*xy + ...

Then I want to extract the first derivative with respect to e.g.x

f_x(x,y) = b+2*c*x + g*y + ...

And then I want to evaluate the first derivative, e.g.

f_x(10,10) = ?

I know you can do some stuff with tensor products of polynomials but I'm not sure how it works

Daniel
  • 167
  • 9
  • It looks kind of straightforward and as if you already wrote down the solution. What do you think is the problem with fitting, extracting the first derivative and evaluating it? To me this looks like it should work more or less exactly like you wrote it. – NoDataDumpNoContribution Oct 24 '19 at 13:14
  • @Trilarion, the problem that I have is that it's two-dimentional (x and y). I know I can fit one dimentional with numpy.polyfit and then find the derivative with numpy.polyder. But these don't woek when you have two dimentions in the explanatory variables – Daniel Oct 24 '19 at 13:23
  • What about a general fit that can work with n dimensions like [scipy.optimize.curve_fit](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html)? – NoDataDumpNoContribution Oct 24 '19 at 13:28
  • 1
    that will probably work to fit any function. but it seems very crude. If I want to fit a 5-degree polynomial with x and y, I have to type all the 15-16 terms... And then getting the derivative seems a nuisance as welll. I was hoping for something that's already built in – Daniel Oct 24 '19 at 13:46
  • 1
    Looks like a duplicate of https://stackoverflow.com/questions/33964913/equivalent-of-polyfit-for-a-2d-polynomial-in-python – Christian K. Oct 24 '19 at 16:44

0 Answers0