Playing around with solving first order linear Differential Equations.
We will presume the DEs are in the form $\frac{dy}{dt} = P(t) y + Q(t)$
reset()
# Solving a first order linear DE in general using Sage
var('t')
y = function('y')(t)
P = function('P')(t)
Q = function('Q')(t)
DE = diff(y,t)==P*y+Q
soln=desolve(DE,y,ivar=t)
show(soln)
# Now, let's try specifying values for P(t) and Q(t) and see what happens
var('t,c')
t0 = 0 # starting point for time
t1 = 3 # ending point for time
y0 = 1 # starting y-value
y = function('y')(t)
P = function('P')(t)
Q = function('Q')(t)
P = -1/2
Q = 2*cos(t)
DE = diff(y,t)==P*y+Q
soln=desolve(DE,y,ivar=t,ics=[t0,y0])
show(soln.expand())
G=points(desolve_rk4(DE, y, ics=[t0,y0], ivar=t, end_points=3, step=0.25))
G+=plot(soln,t,[t0,t1])
show(G)