First-Order Ordinary Differential Equations

Using DSolve to Find  Symbolic Solutions to Differential Equations: General Homogeneous Case

Mathematica can solve the the general homogeneous first-order linear ODE:

DSolve[y'[x] + p[x] y[x] ==0,y[x],x]

The dummy integration variables  (K[1] in the above) and any integration constants  (C[1] above) are picked by Mathematica .  Note that we asked Mathematica to solve the most general form of homogeneous linear first-order ODE, and we got a solution in a very general form that is equivalent to that found in textbooks.  Here is a more specific problem and the solution found by Mathematica:

DSolve[y'[x]+(2 x+1)y[x] ==0, y[x],x]

There is an integration constant above, that will take on a specific value if an additional condition (such as an initial condition, or a boundary condition) is specified. Below, we stipulate that y[0] is 4; so we should get the result with C[1] specified; y[0] = C[1] = 4

DSolve[{y'[x]+(2 x+1)y[x] ==0,y[0]==4}, y[x],x]

DSolve and the General Linear Heterogeneous Case

Mathematica can solve the heterogeneous linear ODE:

DSolve[y'[x] + p[x] y[x] ==r[x],y[x],x]

Again, we asked Mathematica to solve the most general form of homogeneous linear first-order ODE, and we got a solution in a very general form—two dummy integration variables and one constant of integration. Below, we ask for a specific solution for the heterogeneous case: note that the homogeneous solution can always be added to the specific solution.

homsol = DSolve[y'[x] - y[x] ==0,y[x],x]
hetsol = DSolve[y'[x] - y[x] ==(E^(2x)),y[x],x]

Example of Transformation of Variables in Symbolic Differential Equations:The Bernoulli Equation

The Bernoulli equation is a first-order nonlinear ODE that has a form that can be reduced to a linear ODE as described in Kreyszig

BernoulliEquation = y'[x] + p[x] y[x] == r[x] (y[x])^(a)

The substitution y(x) = (((u(x)))^(1/(1-a)))is made, resulting in a linear ODE that can be solved for u(x):

Here we define symbols that will be used in a subsequent rule-replacement method

yRep = ((u[x])^(1/(1-a)))
DyRep = D[yRep,x]

step1 =BernoulliEquation/.{y[x]->yRep,y'[x] -> DyRep}

step2 =PowerExpand[step1]

step3 =Simplify[step2]

This is the form of the linear homogeneous first-order ODE for which we found the general solution above.

BE=Solve[step3,u'[x]]

This last result is the first-order linear ODE that results from the Bernoulli equation. Its solution gives the function u(x) which can be converted back to y(x) with the relation y(x) = (((u(x)))^(1/(1-a))).

uprime = u'[x]/.BE

usol= u[x]/.DSolve[u'[x] == uprime[[1]],u[x],x]

ysol = (usol[[1]])^(1/(1-a))

BernoulliEquation
Simplify[p[x] ysol + D[ysol,x]]

Numerical Solutions to ODEs

Mathematica cannot find a direct solution to the following nonlinear ODE

eqn = (y'[x]- Exp[-Abs[y[x]]])^2 == y'[x]Exp[-x]

DSolve[ eqn,y[x],x]

NDSolve is a numerical method for finding a solution. An initial condition and the desired range of solution are required.

solution =NDSolve[{eqn,y[0]== -2},y,{x,0,25}]

The results look kind of strange, perhaps, but they are a set of rules that provide a function that interpolates between values.   
    Here is how to find the approximate solution at three different values of x on the specified interval:

y[0.5] /. solution

y[1]/.solution

y[Pi]/.solution

Exploring the Numerical Solution Behavior

PlotVanilla =Plot[Evaluate[y[x]/.solution],{x,0,25},PlotStyle->{{Red,Thick},{Darker[Green],Thick}},PlotLabel-> "Plot"];

PlotReal =Plot[Evaluate[Re[y[x]/.solution]],{x,0,25},PlotStyle->{{Red,Thick},{Darker[Green],Thick}},PlotLabel-> "Real Part"];

PlotIm = Plot[Evaluate[Im[y[x]/.solution]],{x,0,25},PlotStyle->{{Red,Thick},{Darker[Green],Thick}},PlotLabel-> "Imaginary Part"];

GraphicsRow[{PlotVanilla,PlotReal,PlotIm},ImageSize->Large]