Equating symbolic coefficients

I would like to look for a y

feature of ODEy'' - y' - 2y = 4x^2

I made the following script:

syms x A0 A1 A2
ypa = A2*x^2+A1*x+A0; % y_p assume
cyp = diff(ypa,2) - diff(ypa) - 2*ypa % according to ODE
P1 = 4*x^2; P2 = cyp ; % Equating P1 and P2
C = coeffs(P1 - P2,x);
A0 = solve(C(1),A0) 
A1 = solve(C(2),A1) 
A2 = solve(C(3),A2) 

      

I got the correct answer for A2 = -2

. But I didn't get for A0

(should be -3

) and A1

(should be 2

). How can I get them automatically?

PS I am using MATLAB R2013a.

+3


source to share


1 answer


Instead of calling solve 3 times, once for each equation C

, you have to call it once on the entire system of equations, so that correct substitutions are performed to give you a numerical result for each variable:



>> [A0, A1, A2] = solve(C)

A0 =
-3

A1 =
2

A2 =
-2

      

+2


source







All Articles