MthSc 841, HW 3, Problem 28

4079 days ago by medlock

def ODERHS(t, Y, params): (y, yp) = Y epsilon = params[0] dy = yp dyp = -yp - epsilon * y^3 return (dy, dyp) T = ode_solver(function = ODERHS, algorithm = 'rk8pd', y_0 = [0, 1]) 
       
var('t epsilon') yR0 = function('yR0', t) yR1 = function('yR1', t) 
       
yR0 = desolve(diff(yR0, t, t) + diff(yR0, t) == 0, yR0, [0, 0, 1]) show(yR0) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}-e^{\left(-t\right)} + 1
\newcommand{\Bold}[1]{\mathbf{#1}}-e^{\left(-t\right)} + 1
yR1 = desolve(diff(yR1, t, t) + diff(yR1, t) == - yR0^3, yR1, [0, 0, 0]) show(expand(yR1)) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}-3 \, t e^{\left(-t\right)} - t + \frac{1}{6} \, e^{\left(-3 \, t\right)} - \frac{3}{2} \, e^{\left(-2 \, t\right)} - \frac{3}{2} \, e^{\left(-t\right)} + \frac{17}{6}
\newcommand{\Bold}[1]{\mathbf{#1}}-3 \, t e^{\left(-t\right)} - t + \frac{1}{6} \, e^{\left(-3 \, t\right)} - \frac{3}{2} \, e^{\left(-2 \, t\right)} - \frac{3}{2} \, e^{\left(-t\right)} + \frac{17}{6}
yTT0a = 1 / (sqrt(1 + 2 * epsilon * t)) - exp(-t) yTT0ab = 1 / (sqrt(1 + 2 * epsilon * t)) - (1 + 2 * epsilon * t) ^ (3/2) * exp(-t) 
       
epsilon = 0.1 tMin = 0 tMax = 20 T.ode_solve(t_span = [tMin, tMax], params=(epsilon, ), num_points=1000) (tN, YN) = zip(*T.solution) (yN, ypN) = zip(*YN) PN = line(zip(tN, yN), color = 'blue') PR0 = plot(yR0, (t, tMin, tMax), color = 'red') PR1 = plot(yR0 + epsilon * yR1, (t, tMin, tMax), color = 'green') PTT0a = plot(yTT0a(epsilon = epsilon), (t, tMin, tMax), color = 'orange') PTT0ab = plot(yTT0ab(epsilon = epsilon), (t, tMin, tMax), color = 'purple') show(PN + PR0 + PR1 + PTT0a + PTT0ab)