Polynomial using linear least squares fitting

1 次查看(过去 30 天)
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.

采纳的回答

Bruno Luong
Bruno Luong 2018-9-29
编辑:Bruno Luong 2018-9-29
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 个评论
jiang tao
jiang tao 2018-9-29
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).

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2018-9-29
编辑:Walter Roberson 2018-9-29
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 个评论
Bruno Luong
Bruno Luong 2018-9-29
编辑:Bruno Luong 2018-9-29
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).
Walter Roberson
Walter Roberson 2018-9-29
编辑:Walter Roberson 2018-9-29
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by