0

Say my equation is

c2 - 2*c1 - 3*n + c1*n + 8*2^n*c3 - 2^n

when I do coeffs(eq,n)I get [ c2 - 2*c1 + 8*2^n*c3 - 2^n, c1 - 3]instead of [ c2 - 2*c1 , 8*c3 - 1, c1 - 3]

all I want to do is equate the coefficients to zero and get three equations like so

c2 - 2*c1 == 0
8*c3 - 1 == 0
c1 - 3 == 0

solve these three equations and substitute the values of c1,c2,c3 in another equation. How do I make coeffs work that way?

Here is my semi-functional code

eqn = v(1) * sym('y_(n+2)') + v(2) * sym('y_(n+1)') + v(3) * sym('y_(n)') - v(4);
eq = simplify(subs(eqn, [sym('y_(n+2)') , sym('y_(n+1)'),sym('y_(n)')],[y_n2,y_n1,y_n]))
c = simplify(coeffs(eq,n));
[c1 c2 c3] = solve(c(1),c(2),c(3),'c1,c2,c3');
ps = subs(y_n);

Here I am hardcoding that there will be three equations and three variables. How do I do it for a general case?

Souradeep Nanda
  • 3,116
  • 2
  • 30
  • 44

0 Answers0