problem with coeffs command

31 次查看(过去 30 天)
Ali Kiral
Ali Kiral 2026-2-5,14:21
评论: Ali Kiral about 22 hours 前
I have a symbollic expression
5*w - 5*z - u*((603367941593515*x)/4503599627370496 - y/2) - v*(x/2 + (603367941593515*y)/4503599627370496) - 1/8
which I want to extract the coefficient of u from. But the coeff command gives an erroneous result:
ans =
5*w - 5*z - u*((603367941593515*x)/4503599627370496 - y/2) - v*(x/2 + (603367941593515*y)/4503599627370496) - 1/8
coeffs(ans,u)
ans =
[5*w - 5*z - v*(x/2 + (603367941593515*y)/4503599627370496) - 1/8, y/2 - (603367941593515*x)/4503599627370496]
The first 'ans' is a multilinear polynomial in x y z u v and w, so shouldn't this work as coeffs is for polynomials.

采纳的回答

Paul
Paul about 22 hours 前
syms w z u y v x
5*w - 5*z - u*((603367941593515*x)/4503599627370496 - y/2) - v*(x/2 + (603367941593515*y)/4503599627370496) - 1/8
ans = 
coeffs(ans,u).'
ans = 
The second term in the result is the coefficient of u and the first term is everything else.
Is that not the expected result?
  4 个评论
Steven Lord
Steven Lord 13 minutes 前
The coeffs(ans, u) function essentially extracts the coefficients for the and terms.
That's true if called with two outputs. If not it returns them in the opposite order, and .
syms w z u y v x
expr = 5*w - 5*z - u*((603367941593515*x)/4503599627370496 - y/2) - v*(x/2 + (603367941593515*y)/4503599627370496) - 1/8;
oneOutput = coeffs(expr, u);
[twoOutputs, terms] = coeffs(expr, u);
isequal(oneOutput, twoOutputs) % false
ans = logical
0
isequal(flip(oneOutput), twoOutputs) % true
ans = logical
1
Ali Kiral
Ali Kiral about 4 hours 前
@Paul I didn't know this command also gives an output for the zeroth power of u. You're right.

请先登录,再进行评论。

更多回答(0 个)

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by