Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
963 views

#Differential Equations

A differential equation is an equation that involves one or more derivatives of an unknown function. These equations arrise naturally in most science diciplines. We will be concerned mostly with First Order Differential Equations, equations where the highest derivative on the unknown function is the first derivative. In general a First Order Differential Equation has the form,

dydx=f(x,y)\frac{dy}{dx}=f(x,y)

Where ff is some function of our dependent variable xx and unknown function y=y(x)y=y(x). The function ff can take on many different forms. Some examples include:

  1. dydx=2x\displaystyle \frac{dy}{dx}=2x

  2. dydx=3xsin(x)+1\displaystyle \frac{dy}{dx}=3x\sin(x)+1

  3. dydx=y\displaystyle \frac{dy}{dx}=\sqrt{y} Toricelli's Law of Water Flow

  4. dvdt=gt\displaystyle \frac{dv}{dt}=-gt Simple gravitational motion, gg gravitational acceleration, vv velocity

  5. dvdt=kvgt\displaystyle \frac{dv}{dt}=kv-gt Simple gravitational motion with wind resistance

  6. dPdt=kP(CP)\displaystyle \frac{dP}{dt}=kP(C-P) Logistic population growth, PP population, CC carrying capacity of environment.

  7. dydt=sin(x)1+x2\displaystyle \frac{dy}{dt}=\frac{\sin(x)}{1+x^{2}}

  8. dTdt=k(AT)\displaystyle \frac{dT}{dt}=k(A-T) Newton's Law of Cooling, AA Ambinent Temperature, TT Temperature, kk proportionality constant

###Solutions of Differential Equations

A solution to a differential equation is a differentiable function y(x)y(x) that satisfies the differential equation. For example, let's look at the differential equation, dydx=2xy\displaystyle \frac{dy}{dx}=2xy. The function y(x)=ex2y(x)=e^{x^2} is a solution. Let's verify this:

dydx=ex2(2x)=2xex2=2xy\frac{dy}{dx}=e^{x^{2}}\cdot(2x)'=2xe^{x^{2}}=2xy

Notice that y(x)=Cex2y(x)=Ce^{x^{2}} is also a solution for any real number CC. A family of solutions like this with an arbitrary constant is called a General Solution.

###First Order Solutions Part 1

Let's consider first order differential equations of the form, dydx=f(x)\frac{dy}{dx}=f(x) where the function ff does not depend on the unknown function. Differential equations like these can be solved directly by integration.

dydx=f(x)\frac{dy}{dx}=f(x)dydxdx=f(x)dx\int\frac{dy}{dx}dx=\int f(x)dxy(x)=f(x)dx+Cy(x)=\int f(x)dx +C

Remark: The arbitrary constant of integration gives us the general solution of our differential equation.

###Example 1

Consider the differential equation dydx=3sin(πx)+x2\displaystyle \frac{dy}{dx}=3\sin(\pi x)+x^{2}. The right hand side is independent of yy, the unknown function. Thus we can solve by direct integration. y(x)=3sin(πx)+x2dx=3πcos(πx)+13x3+Cy(x)=\int 3\sin(\pi x)+x^{2}dx=-\frac{3}{\pi}\cos(\pi x)+\frac{1}{3}x^3+C

Sage can be used to ingegrate this as well:

integral(2*sin(pi*x)+x^2,x) #Notice no Arbitrary constant is given
1/3*x^3 - 2*cos(pi*x)/pi

We can tell sage to solve the differential equation. First we tell Sage that yy is a function of xx. Then we use the desolve\verb+desolve+ command. This command takes two inputs, the differential equation, and the unknown function yy.

y=function('y',x) #Tell Sage that y is a function of x desolve(derivative(y,x)==3*sin(pi*x)+x^2,y)
1/3*x^3 + _C - 3*cos(pi*x)/pi
Notice that Sage gives us the arbitrary constant from integration. Giving different values of the arbitrary constant C we can visualize the family of solutions.
#Plots Family of Solutions, This routine ONLY only works for equations of the form dy/dx=f(x) y(x)=-3/pi*cos(pi*x)+(1/3)*x^3 #Solution without C a=0 #Left part of graph x=a b=pi #Right part of graph x=b n=10 #Number of graphs to plot cMin=-10 #Starting value of C cMax=20 #Ending Value of C DeltaC=(cMax-cMin)/(n-1) plots=plot(y(x)+(cMin),x,a,b) for i in [1..n-1]: plots=plots+plot(y(x)+(cMin+DeltaC*i),x,a,b) show(plots)

###Initial Value Problems

An Initial Value Problem is a differential equation with an extra piece of information (the initial value) that picks out a particular value for our arbitrary constant. For example, we can add the condition y(1)=0y(1)=0 to our previous differential equation to get the initial value problem:

dydx=3sin(πx)+x2,3333y(1)=0\frac{dy}{dx}=3\sin(\pi x)+x^{2},\phantom{3333} y(1)=0

Visually, this solution is the one particular solution that "flows" through the point (1,0). To find the value of CC that corresponds to this solution, we plug in 0 for yy and 11 for xx.

0=y(1)=3πcos(π)+1313+C0=y(1)=-\frac{3}{\pi}\cos(\pi)+\frac{1}{3}1^3+C

Solving for CC we get C=133πC=-\frac{1}{3}-\frac{3}{\pi}

Thus the solution to our initial value problem is, y(x)=3πcos(πx)+13x3133π\displaystyle y(x)=\frac{3}{\pi}\cos(\pi x)+\frac{1}{3}x^3-\frac{1}{3}-\frac{3}{\pi}.

y(x)=-3/pi*cos(pi*x)+(1/3)*x^3 a=0 b=pi n=10 cMin=-10 cMax=20 DeltaC=(cMax-cMin)/(n-1) plots=plot(y(x)+(cMin),x,a,b) for i in [1..n-1]: plots=plots+plot(y(x)+(cMin+DeltaC*i),x,a,b) plots+plot(y(x)-1/3-3/pi,a,b,color='red')

Notice that our "particular solution" passes through the point (1,0) as desired. We can use the desolve\verb+desolve+ command to solve initial value problems as well. Here after the yy term, we add the initial conditions as a pair within brackets.

y=function('y',x) #Tell Sage that y is a function of x f(x)=desolve(derivative(y,x)==3*sin(pi*x)+x^2,y,[1,0]) #The [1,0] addition tells desolve to use the initial condition y(1)=0 f(x)
-1/3*(pi - pi*x^3 + 9*cos(pi*x) + 9)/pi

#Differential Equations Part 1 Assignment

###Question 1

For the two following differential equations:

  • Find the general solution by hand, type in LaTeX\LaTeX.

  • Use the desolve\verb+desolve+ command find the general solution using Sage.

  • Give a plot of a family of solutions. Pick an interval that looks representative of the solutions. (You may need to experiment different values here.)

  • By hand, find the Constant CC that satisfies the initial value problem. Verify that your constant is the same using Sage.

  • Plot your paricular solution using a range that includes the initial value point and demonstrates a representative portion of the solution.

  1. dydx=x+1\displaystyle \frac{dy}{dx}=\sqrt{x+1}, y(2)=3\displaystyle y(2)=3

  2. dydx=xex\displaystyle \frac{dy}{dx}=xe^{-x}, y(1)=3\displaystyle y(-1)=3

###Question 2

For the two following differential equations:

  • Find the general solution using Sage

  • Solve the initial value problem using Sage.

  • Plot your solution using a range that includes the initial value point and demonstrates a representative portion of the solution.

  1. dydx=(x2+3x1)sin(x)\displaystyle \frac{dy}{dx}=(x^2+3x-1)\sin(x), y(π)=4\displaystyle y(\pi)=4

  2. dxdt=e0.5tcos(3t)\displaystyle \frac{dx}{dt}=e^{-0.5t}\cos(3t), x(1)=3\displaystyle x(-1)=-3

  3. dhdx=x3exsin(6x)\displaystyle \frac{dh}{dx}=x^3e^{-x}\sin(6x), h(6)=1\displaystyle h(6)=-1