Polynomial using linear least squares fitting

I want to determining an objective polynomial P(s) by the condition
P(s)=P_pie(s)/(2*sqrt (real (ZL(s))))
P_pie(s) is a polynomial ,P_pie(s)=s-1.266i; ZL(s) is a function of s, which is complex.
the order of P(s)is 4 , so it not only shares the zeros of P_pie(s) but also possibly incorporates extra zeros caused by the ZL(s).
I use polyfit function get the wrong roots of P(s),so I want fix one roots 1.266i of P(s),what linear least squares fitting function should I use to fit P(s).
sorry for my poor English.

 Accepted Answer

Here is the code of fitting a (complex) polynomial to a (complex) data by imposing one root. It can be extended to more roots if you like.
knownroot = 1.266i;
order = 4;
% Generate some fake data
xdata = rand(1,100)-0.5;
Q = rand(1,order) + 1i*rand(1,order);
P = conv(Q,[1 -knownroot]);
ydata = polyval(P,xdata);
% add noise
ydata = ydata + 0.05*(randn(size(ydata)) + 1i*randn(size(ydata))) ;
clear P Q % forget how the polynomial are generated
% Engine
Ppie = [1 -knownroot];
V = xdata(:).^(order:-1:0);
M = conv2(V, flip(Ppie), 'valid');
Q = (M \ ydata(:)).';
P = conv(Q,Ppie);
% Check if the knownroot is attained
min(abs(roots(P)-knownroot))
% visual check if fitting is alright
close all
xi = linspace(min(xdata),max(xdata),200);
yi = polyval(P,xi);
subplot(1,2,1);
plot(xi,real(yi),'r',xdata,real(ydata),'.b');
subplot(1,2,2);
plot(xi,imag(yi),'r',xdata,imag(ydata),'.b');

1 Comment

Wow,Thank you for helping me solve the problem so seriously.Your code is really good. what I is similar to you. I use the Polyfit function to get the polynomial fit of P_inter(s)=1/(2*sqrt (real (ZL(s))));set the order 3,then use the fitting polynomial P_inter(s) multi by P_pie to get my objective polynomial P(s).

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 29 Sep 2018
Edited: Walter Roberson on 29 Sep 2018
You have sqrt() of a function of s. sqrt() only potentially results in a polynomial if the function happened to be raised to an even power (and then you have to worry about sign, as sqrt(x^2) is like sign(x)*x )
You then have that in the denominator. Even if the sqrt() happened to result in a polynomial, the only time you can have function in the denominator and have the result be a polynomial is if the function being divided by is a numeric constant or happens to be the reciprocal of a polynomial.
In other words, it is very likely that you do not have a polynomial and so you cannot use linear least squares. You will need to use nonlinear least squares.
"the order of P(s)is 4"
That is quite unlikely. ZL(s) would have to be a polynomial raised to -2 and P_pie would have to be a polynomial of degree 2.

4 Comments

I use the Polyfit function to get the polynomial fit of P_inter(s)=1/(2*sqrt (real (ZL(s))));set the order 3,then use the fitting polynomial P_inter(s) multi by P_pie to get my objective polynomial P(s).Could I solve this way?
Your ZL is a polynomial, so it has as many zeros as its maximum degree, and is infinite at +/- infinity. Taking the sqrt() of that will have zeros and infinities at the same locations. Dividing by that will be infinite at all the places where it was 0, and zero at the places it was infinite.
This is not something you can reproduce with any polynomial. Every polynomial must be +/- infinity at +/- infinity, but your system will not necessarily be infinite or even defined: it would depend upon the relative rates at which your two polynomials went to infinity.
Your ZL is a polynomial
I don't think he ever said that. If P s polynomial the ZL is a fraction of 2 polynomials (and a square of it).
Ah, correct, they said ZL is a function, without saying it was a polynomial.
Then: in order for the overall system to be reasonably approximated by a polynomial, then ZL would have to be be +/-0 at +/- infinity and non-zero anywhere else -- though oddly it could be infinite in-between, as long as it was non-zero.

Sign in to comment.

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!