352 - Topic 06 - First order linear DEs

869 days ago by Professor352

John Travis

Mississippi College

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) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}{\left(c + \int e^{\left(-\int P\left(t\right)\,{d t}\right)} Q\left(t\right)\,{d t}\right)} e^{\left(\int P\left(t\right)\,{d t}\right)}
\newcommand{\Bold}[1]{\mathbf{#1}}{\left(c + \int e^{\left(-\int P\left(t\right)\,{d t}\right)} Q\left(t\right)\,{d t}\right)} e^{\left(\int P\left(t\right)\,{d t}\right)}
# 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) 
       

                                
                            

                                
show(integrate(2*cos(t)*e^(-1/2*t),t).expand()) 
       

                                
                            

                                
var('w') Plot1=plot_slope_field(1/2*w+2*cos(t),(t,0,10),(w,-6,6))+plot(soln,t,0,3,color='red',thickness=5)+G Plot1.show()