Section 1.3 Separable ODEs

Solve: y’ = y, y(0) = 1, note the use of y[x] and y’[x] and ==

DSolve[{y'[x]==y[x], y[0]==1}, y[x], x]

Solve: y’ = -2xy, y(0) = 1 and 1.8, note the use of y at the end , the solution obtained is a list of functions

DSolve[{y'[x]==-2 x y[x],y[0]==1},y,x]

DSolve[{y'[x]==-2 x y[x],y[0]==1.8},y,x]

Store the solution to a list (sol)

sol=DSolve[{y'[x]==-2 x y[x],y[0]==1.8},y,x]

Use the Replace operator /. to assign the solution  to y[x]

y[x]/. sol

y[1]/.sol

y[0] /. sol

Plot the solution from x = -2 to +2

Plot[y[x] /. sol, {x,-2,2}]

Solve a more complicated ODE: 2xyy’ = y2 - (x^2), C[1] is an arbitrary constant

DSolve[2x y [x]y'[x]==y[x]^2 - x^2,y[x],x]

Solve the ODE: y’ + (x+2) (y^2) = 0

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

Solve the system: A <--> B (kf and kr are forward and reverse rate constants)
[A]’ = -kf [A] + kr [B]. This is an linear equation we will learn to solve.

DSolve[A'[t]+(kf + kr)A[t]-kr A0 ==0,A[t],t]

with the initial condition (Subscript[[A], t=0]) = (Subscript[A, 0])

sol=DSolve[{A'[t]+(kf + kr)A[t]-kr A0 ==0,A[0]==A0},A[t],t]

Setting the constants

A0 = 1.0; kf = 2.0; kr =1.0

Plot the concentrations of A and B as functions of time

Plot[{A[t],A0-A[t]} /.sol, {t,0,3},PlotRange->{{0,2},{0,1}},AxesLabel->{time,concentration}]

Here is a problem we can solve now: A + A --> B (rate constant = k)
A’ = -k (A^2)

eqn=A'[t]==-k A[t]^2

sol=DSolve[{eqn, A[0]==A0},A[t],t]

Clear[A0,k]

Solve[A[t]==A0/2 /. sol,t]

A0=0.1; k=0.2;

Plot[A[t] /.sol, {t,0,100},PlotRange->{{0,100},{0,0.1}},AxesLabel->{time,concentration}]

thalf=1/(A0 k)

A[t]/. sol

A'[t] /. sol

sol=DSolve[{eqn, A[0]==A0},A,t]

A[t]/. sol

A'[t] /. sol

A[50] /. sol