Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
31 views
# Solving an ODE ( Analytically - General Solution ) # example y’=tan(y)/(x-1) y = function ('f')(x) # defines the solution as a function de = diff (y,x) == cos(x)-cot(x)*y # defines the differential equation h = desolve (de , y) # solves analytically ( when possible ) show (h) # shows implicit solution show (solve (h,y)) # shows solution if its a function # This is the general solution as we did not give initial conditions
cos(x)22C2sin(x)\displaystyle -\frac{\cos\left(x\right)^{2} - 2 \, C}{2 \, \sin\left(x\right)}
[]
# section 2.1 number 28 # Solving an IVP ( Analytically - Specific Solution ) # example y’=cos(x)-cot(x)*y y(pi/2) =1 y = function ('f')(x) # defines the solution as a function de = diff (y,x) == cos(x)-cot(x)*y # defines the differential equation h = desolve (de , y, ics =[pi/2,1]) # solves analytically ( when possible ) show (h) # shows right hand side of solution show (solve (h,y)) # shows solution if its a function # This is the particular solution as we gave initial conditions
cos(x)222sin(x)\displaystyle -\frac{\cos\left(x\right)^{2} - 2}{2 \, \sin\left(x\right)}
[]
#3 question #plotting graph for above solution # Plotting a sequence of solution curves with a direction field for an ODE # example y'+2*y=-x^2*e^(-2*x) which has solutions y=e^(-2*x)*(x^4/4+C) x,y= var('x,y') I=sum( plot (-(cos(x)^2-2*c)/(2*sin(x)),(x,.5,2.0)) for c in range (-5,10)) #varies the constant c in the general solution y=e^( -2*x)*(x ^4/4+ c) D= plot_slope_field(cos(x)-2*cot(x)*y ,(x,0.5,2.0),(y , -10 ,15),headaxislength=3, headlength =3) # plots the direction field (solve for y' and put in right hand side) P= plot (-(cos(x)^2-2)/(2*sin(x)),(x,0.5,2.0),color='orange', thickness=3) #emphasizes a specific solution in orange show (I+D+P)