# Polynomial Fit of Rational Function

Given $n$ data points $(x_i,y_i)$ for $i = 1,\dots,n$ and polynomial $p(x)$ of degree $d$. What is the best way to numerically fit: $$\frac{p(x)}{p(x)+1} = y$$ How would I do this in Matlab (in case it's easier to write code)?

As I said in comments, the procedure proposed in Αδριανός's answer is the first step to be used since it makes the problem linear with respect to model parameters. However, a second step consisting in a nonlinear regression is required because what has been measured is $y$ and not $z=\frac{y}{1-y}$.

To illustrate the problem, I generated $51$ equally spaced data points $(0\leq x\leq 5)$ according to $$y=\frac{1}{100} \left\lfloor100 \frac{x^2+2 x+3}{x^2+2 x+4}\right\rfloor$$

Working with the $z$ values, the quadratic polynomial is given by $$p(x)=0.739154 x^2+2.28957 x+2.8133$$ Recomputing the $y$ values, this leads to a sum of squares equal to $0.000693$.

Now, using the above parameters as estimates for the nonlinear regression based on the $y$ values leads to $$p(x)=0.848136 x^2+1.93892 x+2.94349$$ which corresponds to a sum of squares equal to $0.000499$ which makes a significant difference for small errors.

Edit

Just for illustration puposes, I changed the coefficient $100$ to $50$. The preiliminary step gives $$p(x)=0.25453 x^2+3.77357 x+1.80677$$ which corresponds to a sum of squares equal to $0.019893$ while the nonlinear regression gives $$p(x)=0.688777 x^2+1.98693 x+2.8389$$ which corresponds to a sum of squares equal to $0.001678$.

I would re-arrange the equation to solve for $p(x)$ in terms of $y$.

I think it turns out to be equal to: $\frac{y}{1-y}$. Substitute all of the $y_i$'s into this form, and then use standard polynomial interpolation techniques to fit $p(x_i)=y_i'$.

Sorry, I am typing on a mobile device I will edit this answer to be more comprehensive once I am able to.

• Yes, right. That was much simpler than I thought.
– Jiro
Feb 28, 2016 at 14:46
• This is the preliminary step. In order to be rigorous, you should continue with a nonlinear regression since what is measured is $y$ and not $\frac{y}{1-y}$ Feb 28, 2016 at 14:54
• @ClaudeLeibovici You mean the error measures are different between $y$ and $\frac{y}{1-y}$?
– Jiro
Feb 28, 2016 at 17:30
• @SebastianSchlecht. For sure ! Going throught the first step as you suggest only gives estimates of the parameters. Feb 29, 2016 at 4:48
• @Αδριανός : I agree with Claude Leibovici if the criteria of fitting is to obtain the least mean square residuals relatively to $y$. But is it the criteria really needed ? It's become like a new religion to consider the least squares as the best criteria. However, in practical applications, it is far to be always the case. Try the simplest way, that is without nonlinear regression and see if the result of fitting is convenient for you. Do not compute the mean square residuals, but for example the mean absolute residuals, or the mean relative residuals, or any other better fitting criteria. Feb 29, 2016 at 6:40