Skip to main content
deleted 95 characters in body
Source Link
Akku14
  • 17.4k
  • 16
  • 32

Another elegantIf you do it the following way is to use "Unevaluated" to, applying the C[i]shown rules, since "Unevaluated" works only when it appears and is not propagatedyou get the desired result.

This can be used for all types of equations.

 dsol = First@DSolve[y''[x] - 4 y[x] == 1, y, x] /. C[u_] -> Unevaluated[C[u]] (* {y -> Function[{x}, -(1/4) + E^(2 x) C[1] + E^(-2 x) C[2]]} *) sol = First@Solve[{y[0] == a, y'[0] == b} /. dsol, {C[1], C[2]}] (* {C[1] -> 1/8 (1 + 4 a + 2 b), C[2] -> 1/8 + a/2 - b/4} *) ys[x_, a_, b_] = (y[x] /. dsol /. sol) (* -(1/4) + (1/8 + a/2 - b/4) E^(-2 x) + 1/8 (1 + 4 a + 2 b) E^(2 x) *) 

Another elegant way is to use "Unevaluated" to the C[i], since "Unevaluated" works only when it appears and is not propagated.

This can be used for all types of equations.

 dsol = First@DSolve[y''[x] - 4 y[x] == 1, y, x] /. C[u_] -> Unevaluated[C[u]] (* {y -> Function[{x}, -(1/4) + E^(2 x) C[1] + E^(-2 x) C[2]]} *) sol = First@Solve[{y[0] == a, y'[0] == b} /. dsol, {C[1], C[2]}] (* {C[1] -> 1/8 (1 + 4 a + 2 b), C[2] -> 1/8 + a/2 - b/4} *) ys[x_, a_, b_] = (y[x] /. dsol /. sol) (* -(1/4) + (1/8 + a/2 - b/4) E^(-2 x) + 1/8 (1 + 4 a + 2 b) E^(2 x) *) 

If you do it the following way, applying the shown rules, you get the desired result.

This can be used for all types of equations.

 dsol = First@DSolve[y''[x] - 4 y[x] == 1, y, x] (* {y -> Function[{x}, -(1/4) + E^(2 x) C[1] + E^(-2 x) C[2]]} *) sol = First@Solve[{y[0] == a, y'[0] == b} /. dsol, {C[1], C[2]}] (* {C[1] -> 1/8 (1 + 4 a + 2 b), C[2] -> 1/8 + a/2 - b/4} *) ys[x_, a_, b_] = (y[x] /. dsol /. sol) (* -(1/4) + (1/8 + a/2 - b/4) E^(-2 x) + 1/8 (1 + 4 a + 2 b) E^(2 x) *) 
Source Link
Akku14
  • 17.4k
  • 16
  • 32

Another elegant way is to use "Unevaluated" to the C[i], since "Unevaluated" works only when it appears and is not propagated.

This can be used for all types of equations.

 dsol = First@DSolve[y''[x] - 4 y[x] == 1, y, x] /. C[u_] -> Unevaluated[C[u]] (* {y -> Function[{x}, -(1/4) + E^(2 x) C[1] + E^(-2 x) C[2]]} *) sol = First@Solve[{y[0] == a, y'[0] == b} /. dsol, {C[1], C[2]}] (* {C[1] -> 1/8 (1 + 4 a + 2 b), C[2] -> 1/8 + a/2 - b/4} *) ys[x_, a_, b_] = (y[x] /. dsol /. sol) (* -(1/4) + (1/8 + a/2 - b/4) E^(-2 x) + 1/8 (1 + 4 a + 2 b) E^(2 x) *)