coeffs of symbolic equation

1 view (last 30 days)
ahmad ahmadi
ahmad ahmadi on 12 May 2021
Commented: ahmad ahmadi on 12 May 2021
Hi gusy
in this code the coeffes of x or y can extracted, but coeffes of x*y or x*y^2 can't obtain with coffes(), do you have any idea?
syms x y
z=x+2*x*y+4.*y+5*x*y^2;

Accepted Answer

Paul
Paul on 12 May 2021
Edited: Paul on 12 May 2021
Is this what you're looking for:
syms x y
z=x+2*x*y+4.*y+5*x*y^2;
[cxy,t]=coeffs(z,[x y])
cxy = 
t = 
  3 Comments
Paul
Paul on 12 May 2021
syms x y
z=x+2*x*y+4.*y+5*x*y^2;
[cxy,t]=coeffs(z,[x y])
cxy = 
t = 
cxy(logical(t == x*y^2))
ans = 
5
cxy(logical(t == y^2*x))
ans = 
5
ahmad ahmadi
ahmad ahmadi on 12 May 2021
Thanks. It is answer

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!