December 2017
Intermediate to advanced
386 pages
10h 42m
English
We compute each step sequentially and compare it to the actual solution, which is known. You will notice that there is virtually no difference:
import numpyfrom scipy.integrate import odef=lambda t,y: -20*y # The ODEactual_solution=lambda t:numpy.exp(-20*t) # actual solutiondt=0.01 # time stepsolver=ode(f).set_integrator('dop853') # solversolver.set_initial_value(1,0) # initial valuewhile solver.successful() and solver.t<=1+dt: # solve the equation at successive time steps, # until the time is greater than 1 # but make sure that the solution is successful print (solver.t, solver.y, actual_solution(solver.t)) # We compare each numerical solution with the actual # solution of the ODE solver.integrate(solver.t + dt) # solve next ...Read now
Unlock full access