Desolve RK4

Description

We can use the desolve_rk4() command to nummerically solve any first order ODE. This command in particular is useful because of its variety of output options: we may change the output argument to list for a list of ordered pairs predicted to be on the solution curve, 'plot' for an approximate plot of the solution curve, or 'slope_field' for the same plot from 'plot' laid over the slope field of the differential equation. The command mostly has the same arguments as desolve, with additional fields output, which we already mentioned, and end_points, with which you specify the interval over which you are approximating.

Sage Cell

Code

var('t')
y = function('y')(t)
de = diff(y, t) == sin(t)^2*y
desolve_rk4(de,dvar=y, ivar=t, end_points=[0, 6], ics=[0, 1], output='list')

Options

Other Output Options

Here, we'll run the command again with output=plot:

Code

var('t')
y = function('y')(t)
de = diff(y, t) == sin(t)^2*y
desolve_rk4(de,dvar=y, ivar=t, end_points=[0, 6], ics=[0, 1], output='plot')

Then again with output='slope_field'

The slope field outputted here does not have direction indicators on the slope vectors, so depending on your purposes it may be better to superimpose the plot output over a separately plotted vector field for more control over the plot features.

Code

var('t')
y = function('y')(t)
de = diff(y, t) == sin(t)^2*y
desolve_rk4(de,dvar=y, ivar=t, end_points=[0, 6], ics=[0, 1], output='plot')

Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

Attribute

Permalink:

Author:

Date: 13 May 2020 05:35

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License