Preface
This tutorial was made solely for the purpose of education and it was designed for students taking Applied Math 0330. It is primarily for students who have very little experience or have never used Mathematica before and would like to learn more of the basics for this computer algebra system. As a friendly reminder, don't forget to clear variables in use and/or the kernel.
Finally, the commands in this tutorial are all written in bold black font, while Mathematica output is in regular fonts. This means that you can copy and paste all comamnds into Mathematica, change the parameters and run them. You, as the user, are free to use the scripts to your needs for learning how to use the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to Mathematica tutorial for the second course APMA0340
Return to the main page for the course APMA0330
Return to the main page for the course APMA0340
Return to Part II of the course APMA0330
Separable Equations
A differential equation \( y' = f(x,y) \) is said to be separable if the slope function is the product of two functions depending on only one variable: \( f(x,y) = p(x) q(y). \) Then rewriting the derivative y' in differential form \( y' = {\text d}y / {\text d}x , \) we separate variables:
Example: The general solution to the equation \( y' = x^2/y^2 /\sqrt{4-x^2} \) is found by separation of variables
y -> Function[{x}, (3/2)^(1/3) (-x Sqrt[4-x^2] + 4 ArcSin[x/2] + 2 C[1])^(1/3)],
y -> Function[{x}, (-1)^(2/3) (3/2)^(1/3) (-x Sqrt[4-x^2] + 4 ArcSin[x/2] + 2 C[1])^(1/3)]}
Example: Consider separable differential equation: \( y'= xy/(1+x^2 ). \) First, we separate variables and integrate
DSolve[{y'[x] == x*y[x]/(x^2 + 1)}, y[x], x]
Plot[{Sqrt[1 + x*x], 4*Sqrt[1+x*x], 0.4*Sqrt[1+x*x], 8*Sqrt[1+x*x]}, {x, 0, 5}, PlotLabel -> "Solutions to Example 1.3.1 "]

In this command sequence, the first line of code asks Mathematica to find the solution to this separable differential equation.
The second line contains commands to plot different possible solutions to this separable differential equation based on the value of the integration constants. None of the subcommands of Plot are new in this command sequence and they have already been explained earlier.
We would like to use advantage of knowing Mathematica to solve the equation by direct integration and to then plot those solutions:
Clear[t,y];
t0 = 0; y0 = 2; f[t_] = t/(1 + t^2); g[y_] = 1/y; (* define the initial values and the slope functions *)
gensol = Solve[G[y] == F[t] + c, y];
const = Solve[y == y0 /. gensol /. t -> t0, c];
sol[t_] = y /. gensol /. const[[1]] (* solution of the IVP *)

In this syntax, the first command, Clear, clears out any previously existing values for the two variables, allowing you to redefine them.
The second command defines the different initial conditions and the two functions that you are trying to solve.
The first command line tells Mathematica which functions you want to integrate.
The fourth and fifth lines of codes tell Mathematica how you want to define the general solution and how you want to solve for the integration constant c.
The sixth line gives the final solution to this separable differential equation (this is also an initial value problem).
The final line tells Mathematica which function to plot and the range.
In Mathematica, as this example shows, you can insert comments to the commands by adding a comment surrounded by stars as in (* solution of the IVP *) and then parentheses. Even when variables can be separated, the final solution might be accompanied by a warning message from Solve, or it might only be given as an InverseFunction object.
Example: Consider separable differential equation: y' +ycos(x) =0
Plot[Evaluate[toplot], {x, 0, 4*Pi}]

Example: Consider separable differential equation: x(y+1)(y-3) dx +(1+5y)(x+2) dy =0. We solve this equation by separating variables and then integrating:
Example: (Newton's Law of Cooling) Separable equations arise in a wide range of application problems. The time of death of a murder victim is an important question on many popular movies and television programs. How does a forensic scientist or a medical examiner determine the time of death? Human beings have a temperature of 98.6○F or 36.6○C. If the surrounding temperature is cooler, then the body will cool down after death. Eventually, the temperature of the body will match the temperature of the environment. We should not expect the body to cool at a constant rate either. Think of how a hot cup of coffee or tea cools. The liquid will cool quite quickly during the first few minutes but will remain relatively warm for quite a long period.
The answer to our forensic question can be found by using Newton's law of cooling, which tells us that the rate of change of the temperature of a object is proportional to the difference between the temperature of the object and the temperature of the surrounding medium. Newton's law of cooling can be easily stated as a differential equation,
Suppose that the temperature of the surrounding environment is 21○C, and we know from experience that a body under these conditions cools off approximately 1○C during the first hour after death. In order to determine a formula for the time of death, we must solve the initial value problem
Example: A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K. Assuming heat is lost only due to radiation, the differential equation for the temperature of the ball is given by
Example: (Mixing Problems) There is a large class of problems in modeling known as mixing problems. These problems refer to situations where two are more substances are mixed together in a container or containers. For example, we might wish to model how chemicals are mixed together in a refinery, how pollutants are mixed together in a pond or a lake, how ingredients are mixed together when brewing beer, or even how various greenhouse gases mix together across different layers of the atmosphere.
Suppose that we have a large tank containing 4000 liters of water and that water containing 0.01 kg of salt per liter flows into the tank at a rate of 4 liters per minute. If the tank is also draining at a rate of 4 liters per minute, the water level in the tank will remain constant. We will assume that the water in the tank is constantly stirred so that the mixture of salt and water is uniform in the tank.
We can model the amount of salt in the tank using differential equations. If x(t) is the amount of salt in the tank at time t, then the rate at which the salt is changing in the tank is the difference between the rate at which salt is flowing into the tank and the rate at which it is leaving the tank, or