#This is a script that illustrates the basics of analytically solving ODEs
#using Sage.

#Example 1: Defining an ODE and finding a general solution
var('t'); #Declare t as a symbolic variable
u = function('u')(t) #Declare dependent variable u(t)
de = diff(u,t) == u+t #Define the ODE, install in variable "de"
desolve(de,u) #Find the general solution to the ODE

#Example 2: Finding the solution with specified initial data
usol(t) = desolve(de,u,[0,2]) #Compute solution to the ODE "de" with u(0)=2, assign to function "usol"
usol(2) #Evaluate solution at t = 2
plot(usol, (t, 0, 3)).show()

#Example 3: A second order example
de = diff(u,t,2) + 3*diff(u,t) + 2*u == sin(t) #A second order example
usol(t) = desolve(de, u, [0,1,2]) #Solve with u(0)=1, u'(0)=2
plot(usol, (t,0,20)).show()