> > # A nonhomogeneous 2nd order ODE with constant coefficients is # solved from beginning to end using the Method of Undetermined # Coefficients. -------------------------------------------------------------------------------- # # Art Belmonte # Tue, 13/Feb/96 # Math 308-509 (Worksheet A) # Text, Sections 3.6, 4.3: Lecture: The Method of Undetermined # Coefficients # # The LZ procedure provides a short cut to construct linear DEs with # the auxillary equation. # > unprotect(LZ):\ LZ:=proc(c)\ local a, d, k, L, n, p, r, s, x, y, Z;\ n:=nops(c) - 1;\ a:=array(0..n, c);\ p:=0; s:=0;\ for k from 0 to n do\ p:=p + a[k]*r^(n-k);\ s:=s + a[k]*(D@@(n-k))(y)\ od;\ L:=unapply(s, y);\ Z:=unapply(p, r);\ #d:=convert(L(y)(x)=0, diff);\ [eval(L), eval(Z)]\ end;\ protect(LZ):\ \ -------------------------------------------------------------------------------- # Ex 1-0 (S3.6, 162/15): Solution to 2nd order linear # nonhomogenous IVP; setup. > unassign('y'); setup:=LZ([1, -2, 1]);\ L:=setup[1]; Z:=setup[2];\ homog_deq:=convert(L(y)(x)=0, diff);\ nonhomog_deq:=convert(L(y)(x)=x*exp(x)+4, diff);\ IC:={y(0)=1, D(y)(0)=1}; IVP:={nonhomog_deq} union IC; -------------------------------------------------------------------------------- # Ex 1-1: Find general solution, yc, of the corresponding # homogeneous problem. > rt:=solve(Z(r)=0, r);\ y:=unapply(c1*exp(x) + c2*x*exp(x), x);\ yc:=eval(y);\ check:=simplify(homog_deq); -------------------------------------------------------------------------------- # Ex 1-2: Ensure that (the terms of) g(x), the RHS in the # nonhomogeneous DE, is of the form in Table 3.6.1 (T-159) or # Table 4.3.1 (T-204). Otherwise, use the method of variation of # parameters. It is in this case, the method of undetermined # coefficients is the ticket! > rhs(nonhomog_deq); -------------------------------------------------------------------------------- # Ex 1-3: Set up the subproblems, one for each term in g(x). > unassign('y');\ nh1:=convert(L(y)(x)=x*exp(x), diff);\ nh2:=convert(L(y)(x)=4, diff); -------------------------------------------------------------------------------- # Ex 1-4: For each subproblem, assume the form of the particular # solution to the corresponding nonhomogeneous subproblems. # Looking at the Notes beneath Table 3.6.1, we see that s = 2 = # #times alpha=1 is a root of the characteristic equation Z(r)=0. > yp1:=unapply(x^2*(a*x+b)*exp(x), x);\ yp2:=x->c; -------------------------------------------------------------------------------- # Ex 1-5: Find the particular solution to each subproblem. Then sum # them to form a particular solution to the full nonhomogeneous # problem. > simplify(subs(y(x)=yp1(x), nh1));\ sol:=solve(identity(", x), {a, b});\ yp1:=unapply(subs(sol, yp1(x)), x);\ -------------------------------------------------------------------------------- # Ex 1-6: Finally, obtain the general solution to the full # nonhomogeneous problem by adding the general solution to the # homogeneous problem and the particular solution to the full # nonhomogeneous problem. > y:=unapply(yc(x)+yp(x), x);\ check:=simplify(nonhomog_deq); -------------------------------------------------------------------------------- # Ex 1-7: Since this was an IVP, we now determine c1 and c2. > IC; c_sols:=solve(", {c1, c2});\ final_solution; y:=unapply(subs(c_sols, y(x)), x);\ final_check:=IVP; -------------------------------------------------------------------------------- # "Victory at sea..." >