Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168737
Image: ubuntu2004

Checking solutions.

In this tutorial, we show how to check if a function is a solution of a differential equation. As an example, let's consider the equation:

dxdt=tx\displaystyle\frac{dx}{dt} = tx

We start by defining the independent and dependent variables, and an expression defining the right hand side of the differential equation:

t = var('t') x = var('x') derhs = t*x derhs
t*x

We can now compute values of the slope field for the equation:

derhs.subs(t=1,x=2)
2

We know that the solution of the equation will have some exponentials. So, let's try x(t)=etx(t)=e^t:

x1 = e^t diff(x1,t)-derhs.subs(x=x1)
-t*e^t + e^t

We don't get zero, so this is not a solution. Let's try x(t)=et2/2x(t)=e^{t^2/2}:

x2 = e^(t^2/2) diff(x2,t)-derhs.subs(x=x2)
0

The general solution of the equation can be written as x(t)=cet2/2x(t)=ce^{t^2/2}. Let's check this:

c = var('c') x3 = c*e^(t^2/2) diff(x3,t)-derhs.subs(x=x3)
0

Guessing solutions

Many differential equations are solved by guessing the form of the solution. Let's consider the equation:

dxdt=2x+1\displaystyle\frac{dx}{dt} = -2x+1

As before, start by defining the right-hand side of the equation:

t = var('t') x = var('x') eqrhs = -2*x+1 eqrhs
-2*x + 1

We guess that solutions of this equation have an exponential form. We try x(t)=e2t+ax(t)=e^{-2t}+a, where aa is a constant to be determined:

a = var('a') x1 = e^(-2*t)+a diff(x1,t)-eqrhs.subs(x=x1)
2*a - 1

We see that if a=1/2a=1/2 we get 0 (independently of tt). So, x(t)=e2t+12x(t)=e^{-2t}+\frac{1}{2} is a solution. We check this:

x1 = x1.subs(a=1/2) diff(x1,t)-eqrhs.subs(x=x1)
0