Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: test
Views: 87
# Example showing how to solve the 1st ord. ODE: x' = 3/x t = var('t') #x = function('x',t) # This was old style, and is now being phased out x = function('x')(t) DE = diff(x,t) - 3/x desolve(DE, [x,t])
1/6*x(t)^2 == _C + t
# Example showing how to solve the 1st ord. ODE y' + y/4 = 3 + 2cos(2t) t = var('t') y = function('y',t) DE = diff(y,t) + y/4 - 3 - 2*cos(2*t) desolve(DE, [y,t])
1/65*(8*(cos(2*t) + 8*sin(2*t))*e^(1/4*t) + 65*_C + 780*e^(1/4*t))*e^(-1/4*t)
# Example showing how to plot direction fields for the function: x=sin(t), y=cos(t) x,y = var('x,y') plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3))
# Example showing how to plot direction fields for 1st ord. ODE: y' = 2y+4-t t,y = var('t,y') plot_vector_field((1,2*y+4-t), (t,0,3), (y,-4,0))
# Example showing how to solve a 1st ord. ODE with parameters: y' = ay(1-by) t = var('t') y = function('y',t) a = var('a') b = var('b') DE = diff(y,t) + a*y*(1 - b*y) desolve(DE, [y,t])
(log(b*y(t) - 1) - log(y(t)))/a == _C + t
s, i, t = var('s i t') b = 0.26 g = 0.12 n = 100 s0 = 78 i0 = 22 de1 = -b*s*i/n + g*i de2 = b*s*i/n - g*i P = desolve_system_rk4 ([de1, de2], [s, i], ics=[0, s0, i0], ivar=t, end_points=[0,50] ) Q = [ [i,j] for i, j, k in P] R = [ [i,k] for i, j, k in P] list_plot(Q+R)
# Explore test question: # y''' - 5*y'' + 6*y' = 0; y(0)=3, y'(0)=8, y''(0)=22 # y vs t: u,v, w, t = var('u, v, w, t') u0 = 3.0 v0 = 8.0 w0 = 22.0 de1 = v de2 = w de3 = 5*w - 6*v P = desolve_system_rk4 ([de1, de2, de3], [u, v, w], ics=[0, u0, v0, w0], ivar=t, end_points=[0,2] ) Q = [ [i,j] for i, j, k, l in P] P1 = list_plot(Q, plotjoined=true) P2 = plot((exp(2*x)+2*exp(3*x)), (x, 0, 3)) show(P1+P2)