Shared11 - Differential Equations Assignment / Differential Equations Notes.sagewsOpen in CoCalc
This material was developed by Aaron Tresham at the University of Hawaii at Hilo and is

Prerequisites:

• Intro to Sage
• Differentiation

Differential Equations

A differential equation is an equation that contains one or more derivatives. In this lab, we will consider differential equations with only the first derivative, but in general, higher order derivatives may appear as well.

The simplest differential equations may be written in the form:

Solving Differential Equations

To solve a differential equation, we must find the differentiable functions which satisfy the equation.

Example 1

Consider the differential equation . We know has the correct derivative for any constant , so these functions are solutions. In fact, these functions are the only solutions (this is a corollary of the Mean Value Theorem).

For any differential equation of the form , we find the solutions simply by finding the antiderivatives of . In other words the solutions are

Differential equations of the form or may sometimes be solved using a method called separation of variables.

Example 2

Consider the differential equation .

We are going to pretend that is a fraction, and we are going to gather and terms on opposite sides of the equation (cross multiply):

[This is nonsense, but it will work out in the end!]

Now integrate both sides:

Integrating we get:

Solving for gives:

Or writing it another way:

For , this is the equation of a circle centered at the origin of radius .

The slope of a circle at a point on the circle is .

Separation of Variables

In general, a differential equation is separable if it can be written in the form .

In this case, the solutions may be found by solving:

This gives implicitly as a function of . You may be able to solve the resulting equation for .

Note: This technique does not work if (i.e., is the zero function), since the left side of the integral equation is never defined. Remember, we're thinking of as a function of , so is a composition. It's possible that even though neither nor is the zero function.

If is a constant function such that , then this is a solution to the differential equation. However, this solution is eliminated in the above technique. Thus, you have to consider this possibility separately.

This is a subtle point, and since we do not usually care very much about constant solutions, I will ignore this in most of the examples below.

Example 3

Consider the differential equation . This is separable (with and ).

As long as is not the zero function, the solution is given by the equation

Integrating we get

Now solve for :

These solutions may be written

Remember that is an arbitrary constant, so is an arbitrary positive constant.

Thus, is an arbitrary non-zero constant.

So we can write this as , where is an arbitrary non-zero constant.

In fact, if , we get (the zero function). This is actually a solution to the differential equation.

Therefore, the most general solution is for any constant .

Example 4

Consider the differential equation .

This is separable and may be solved by integrating:

Example 5

Consider the differential equation .

First, we may simplify the exponents: .

This is separable and may be solved by integrating:

Example 6

Consider the differential equation .

First, we can factor the right-hand side to see that this is separable:

Therefore, the solutions may be found by integrating:

These solutions may be written , where is any constant (I'll skip the details).

Initial Value Problems

Some differential equations come with "initial conditions," that is, values of a solution and/or its derivatives at some specific point(s).

These conditions may allow us to solve for the "."

Example 7

Consider the initial value problem

We can solve the differential equation with separation of variables ( and ).

Now use the initial condition to solve for .

Plug in and

Therefore, the (unique) solution to the inital value problem is

Solving Differential Equations in Sage

Sage has a command called "desolve" that may be able to solve a first-order differential equation (that's "d-e-solve" for "differential equation solve", not "de-solve").

To use desolve, you must tell Sage that is a function of . Then desolve is similar to the regular solve command. It takes two arguments: a differential equation (with a double equal sign), and a variable to solve for.

Example 3 again

.

y=function('y')(x)
desolve(derivative(y,x)==y,y)
show(_)

_C*e^x

Recall our solution: .

Example 4 again

y=function('y')(x)
desolve(2*sqrt(x*y)*derivative(y,x)==1,y)
show(_)

2/3*(2*sqrt(x*y(x))*y(x) - 3*x)/sqrt(x) == _C

Notice that Sage has given an implicit solution. You still need to solve for . Let's try to get Sage to solve it for us.

I will declare a variable "C," and then I will copy and paste the above solution, removing the underscore in front of the C.

%var C
solve(2/3*(2*sqrt(x*y(x))*y(x) - 3*x)/sqrt(x) == C,y)
show(_)

[y(x) == 3/4*(C*sqrt(x) + 2*x)/sqrt(x*y(x))]
[]

Sage still left us with an implicit solution (notice y(x) on the right side). I don't know why Sage won't solve this completely.

Compare with our solution:

Example 5 again

y=function('y')(x)
desolve(derivative(y,x)==e^(2*x-y)/e^(x+y),y)
show(_)

-e^x + 1/2*e^(2*y(x)) == _C

We have to solve for again.

%var C
solve(-e^x + 1/2*e^(2*y(x)) == C,y)
show(_)

[y(x) == log(-sqrt(2*C + 2*e^x)), y(x) == 1/2*log(2*C + 2*e^x)]
[, ]

Sage has given us a strange answer. Notice that the first "solution" is the log of a negative number (as long as x is a real number), so the second solution is the one we want.

Compare with our solution:

Example 6 again

y=function('y')(x)
desolve(derivative(y,x)==x*y+3*x-2*y-6,y)
show(_)

(_C - 3*e^(-1/2*x^2 + 2*x))*e^(1/2*x^2 - 2*x)

Compare our solution

Although this looks different, it is the same (distribute the multiplication over the subtraction and simplify).

Solving an Initial Value Problem with Sage

You can solve an initial value problem by adding at the end of desolve, where is given.

Example 7 again

.

y=function('y')(x)
desolve(derivative(y,x)==-y^2,y,[0,1/2]) #notice the square brackets
show(_)

(1/y(x)) == x + 2

Once again, Sage left us with an implicit solution. Here's the explicit solution:

solve((1/y(x)) == x + 2,y)
show(_)

[y(x) == (1/(x + 2))]
[]

This is the same answer we got before.

There is a whole class called "Differential Equations" that will introduce you to more complex equations and solution methods.

Next time, we'll look at a method to approximate solutions numerically.