Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equating symbolic coefficients

I would like to seek y particular of ODE y'' - 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 did not get for A0 (should be -3) and A1 (should be 2). How to get them automatically?

P.S I'm using MATLAB R2013a.

like image 581
User1961 Avatar asked May 17 '26 20:05

User1961


1 Answers

Instead of calling solve 3 times, once on each equation of C, you should call it once on the entire system of equations so that the proper substitutions are done to give you a numeric result for each variable:

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

A0 =
-3

A1 =
2

A2 =
-2
like image 162
gnovice Avatar answered May 20 '26 19:05

gnovice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!