Polynomial fitting of the second problem can be realized by polyfit function.
In the form of the first function, the three parameters are the abscissa, ordinate (x, y) and polynomial order (n) of a known point, and p is the polynomial coefficient, arranged in descending order. You can write and calculate fitting polynomials of different orders according to your own needs, and then evaluate the fitting results, which can be evaluated by SSE and other indicators. What are the specific evaluation indicators? You can read this article "Web Link". Then choose the best fitting polynomial, use the root function to find the zero coordinate, and choose the most suitable solution.
P is p in the last polynomial fitting (where the last term minus 0.002 can be taken as p (end) = p (end)-0.002; Implementation), r is the root of polynomial.