How Can I find the Coefficients of a Polynomials by equating Coefficients Method?

16 次查看(过去 30 天)
Hi guys, I have 2 polynomials, one with known coefficients and one with unknown coefficients. Is there any way in Matlab that I can find the unknown coefficients by equating of coefficients of the like power? For instance, P1=2*s^2+1 and P2=a*s^2+b*s+c, to make P1=P2 we will have a=2,b=0 and c=1. Thanks in advance for the help. Cheers,

采纳的回答

Image Analyst
Image Analyst 2014-2-24
If you have a bunch of (s,P1) pairs (at least 3) then you can train a polynomial with polyfit (does a least squares) and it will tell you the best values of a, b, and c to fit your training data. If that what you mean? If not, explain why not.

更多回答(1 个)

John D'Errico
John D'Errico 2014-2-25
编辑:John D'Errico 2014-2-25
Not too difficult, and I am sure there are various better solutions.
syms s a b c
P1=2*s^2+1;
P2=a*s^2+b*s+c;
C = coeffs(P1 - P2,s);
solve(C(1),c)
ans =
1
solve(C(2),b)
ans =
0
solve(C(3),a)
ans =
2
  12 个评论
John D'Errico
John D'Errico 2014-2-27
The point is, there is NO solution to the problem you have posed for most such problems (which contradicts your claims.) I've even shown how to compute a solution IF one exists, despite what seems to be the moving target of your claims.
Suppose I start with your example, but lets look at whether C can ever be a monic polynomial, as you claim?
syms s a b c
A=s^2+s-2;
B=s^2+s;
R=s+a;
S=b*s+c;
C = expand(A*R + B*S)
C =
a*s - 2*s - 2*a + c*s + a*s^2 + b*s^2 + b*s^3 + c*s^2 + s^2 + s^3
Ccoeffs = coeffs(C,s)
Ccoeffs =
[ -2*a, a + c - 2, a + b + c + 1, b + 1]
Hmm. Apparently C is never monic UNLESS b = 0. So if a monic polynomial C is somehow important to you, then the problem reduces to a simpler one.
The point is, I think you don't really know what you want here, or what must happen for a solution to exist. You have just been making random claims, then changing them when I've disproved your claims.
Anyway, lets try a simple version of your problem that actually DOES have a solution. There are some rare cases it might seem. Here I'll arbitrarily construct a problem where
a = 2
b = 0
c = 3
Therefore we would have...
R0 = s + 2;
S0 = 3;
C0 = expand(A*R0 + B*S0)
C0 =
s^3 + 6*s^2 + 3*s - 4
So, for this simple case, can we recover those coefficient for a,b,c? The problem is now well posed.
scoeffs = coeffs(expand(A*R + B*S - C0),s)
abc = solve(scoeffs)
Warning: 4 equations in 3 variables.
> In /Applications/MATLAB_R2014a.app/toolbox/symbolic/symbolic/symengine.p>symengine at 56
In mupadengine.mupadengine>mupadengine.evalin at 97
In mupadengine.mupadengine>mupadengine.feval at 150
In solve at 170
abc =
a: [1x1 sym]
b: [1x1 sym]
c: [1x1 sym]
abc.a
ans =
2
abc.b
ans =
0
abc.c
ans =
3
So IF a solution exists, what I've showed you is how to solve it (and I showed you that long ago.) But my guess is that soon you will have changed the problem. For example, you called this a Diophantine problem before. Did you really mean that?

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by