┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 10.1, Release Date: 2023-08-20 │ │ Using Python 3.10.12. Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘ sage: %colors nocolor sage: sage: def get_soln(y0, yp0, t0, tmax, deltat): ....: soln = {t0:y0} ....: y = y0 ....: t = t0 ....: yp = yp0 ....: while t < tmax: ....: new_t = t + deltat ....: new_y = y + yp * deltat ....: new_yp = yp + F(y,yp,t) * deltat ....: t = new_t ....: y = new_y ....: yp = new_yp ....: soln[t] = y ....: return soln sage: sage: sage: sage: sage: sage: sage: def F(y,yp,t): ....: to_ret = -0.1*yp - y + cos(2.0*t) ....: return to_ret ....: sage: time soln = get_soln(1,0,0,10,0.01) CPU times: user 6.04 ms, sys: 4 µs, total: 6.05 ms Wall time: 6.02 ms sage: sage: points( soln.items(), dpi=400, size=1) Launched png viewer for Graphics object consisting of 1 graphics primitive sage: time soln = get_soln(1,0,0,100,0.01) CPU times: user 153 ms, sys: 3.98 ms, total: 157 ms Wall time: 156 ms sage: sage: points( soln.items(), dpi=400, size=1) Launched png viewer for Graphics object consisting of 1 graphics primitive sage: time soln = get_soln(1,0,0,1000,0.01) CPU times: user 1.04 s, sys: 27 ms, total: 1.07 s Wall time: 1.07 s sage: points( soln.items(), dpi=400, size=1) Launched png viewer for Graphics object consisting of 1 graphics primitive sage: soln = get_soln(1,0,0,1000,0.01) sage: time soln = get_soln(1,0,0,1000,0.01) CPU times: user 846 ms, sys: 12 ms, total: 858 ms Wall time: 857 ms sage: sage: sage: sage: sorted(list(soln.items()))[:10] [(0, 1), (0.0100000000000000, 1.00000000000000), (0.0200000000000000, 1.00000000000000), (0.0300000000000000, 0.999999980000667), (0.0400000000000000, 0.999999880031999), (0.0500000000000000, 0.999999600219293), (0.0600000000000000, 0.999999000869027), (0.0700000000000000, 0.999997902574617), (0.0800000000000000, 0.999996086342000), (0.0900000000000000, 0.999993293734980)] sage: sorted(list(soln.items()))[:1000:100] [(0, 1), (1.00000000000000, 0.866605484524718), (2.00000000000000, -0.269918822354881), (2.99999999999998, -1.47123448297629), (3.99999999999996, -0.689685392749432), (4.99999999999994, 0.544120597317060), (5.99999999999992, 0.680238891382552), (6.99999999999990, 0.720228312181525), (7.99999999999987, 0.208365812658922), (8.99999999999985, -1.02745962234716)] sage: