# How to create and solve a underdetermined nonlinear system of equations using python

as i already mentioned in the header my plan is to create and solve a system of nonlinear equations in python. As I also mentioned, the equations system will be underdetermined.

I will try to give an example for what i plan to do:

1. I have the coefficients of some polynomal fits which i have performed in an earlier step stored in two arrays. Lets say:

A = np.array([[1,2,3], [5,6,8], [8,9,4]])
B = np.array([[2,5,6], [7,4,1], [7,8,6]])


Now i want to build functions with this coefficients (actually these are the functions from the fit i performed in an earlier step). Using the variables x, y and z. The addition of the resulting functions from each of the both arrays shall be equal a certain value. So what i try to explain should look like:

1x^2+2x+3 + 5y^2+6y+8 + 8z^2+9z+4 - 50 = 0
2x^2+5x+6 + 7y^2+4y+1 + 7z^2+8z+6 - 65 = 0


I know i can get each of this functions using np.poly1d giving it x,y or z for the variable input. But i did not manage to sum them up. Also this seems to be not very efficient to me.

3. In the last step i would like to solve this underdetermined system of nonlinear equations to get values for x,y and z. Furthermore i need to set boundaries for each of the variables. For example 2<x<5 (don´t know if this would work for the values i gave here, all of this is just to help me explain what i plan to do). My plan is to find a least square solution of this problem to minimize ||Ax-b||2.

In my actual application I need to solve this for 21 variables (x1to x21) and also the number of equations can differ from two (like in this example) to six.

I would be very happy if someone could help me solving this problem. Thank you all in advance, David

• Can you clarify what do you expect to get as a solution? Underdetermined systems have infinitely many solutions. May 19, 2021 at 12:39
• See stats.stackexchange.com/questions/123930/… for a generic answer.
– whuber
May 19, 2021 at 13:16
• Oh sorry, I would like to find a least square solution which minimizes ||Ax-b||2 May 19, 2021 at 13:50
• In general, this is a non-convex MINLP. There are global MINLP solvers for this problem class. If the nonlinearities are only quadratic, then a solver like Gurobi comes also into play. Jun 2, 2021 at 3:47