Macro Library diffeq

Differential equations functions, Jan 2023

diffeq_slopefield

diffeq_slopefield(function, [options])

Draws a slopefield for the given differential equation.

function: For a first order ODE, like dy/dx=x*y^2, use a single string, like "x*y^2".
For an autonomous system, like x'=x+y, y'=y-2x, list both parts, like "x+y,y-2x"

options is an optional associative array of parameters. You can define none or several of them. There are two common ways to define these:

Inline: $g = diffeq_slopefield("xy",['dx'=>0.5, 'arrows'=>1])

As a separate array:

    $ops['dx'] = 0.5
    $ops['arrows'] = 1
    $g = diffeq_slopefield("xy",$ops)

The options you can set are:

diffeq_comparegensoln

diffeq_comparegensoln(expr1, expr2, vars, constants, [tolerance, domain])

Compares two general solutions to an ODE which contain arbitrary constants. They are compared in a way that allows swapping which constant goes where, and accomodates absorbed constants.

expr1: the first general solution, like "cos(t)+c_1*e^t+c_2*e^(-t)"

expr2: the second general solution

vars: the independent variables in the expression, like "t"

constants: the arbitrary constants in the expression, like "c_1,c_2"

tolerance: the relative tolerance to compare with. Default 0.001.

domain: the domain to compare on. Default "-10,10".