Mathcad Professional 14.1 Linear Ordinary Differential Equation solver Symbolically solves (sets of) Linear Ordinary Differential Equations with constant coefficients Luc Meekes Reference, LODEsolve Luc Meekes 3 D0B990B2-5353-490A-A8FF-9272ABE5D10D B1F3D274-8D31-434B-8433-A966BC85BEC1 00000000-0000-0000-0000-000000000000 00000000-0000-0000-0000-000000000000
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}} {\colortbl ;\red0\green0\blue0;} \viewkind4\uc1\pard\cf1\f0\fs16 Date: \{fd\}; Time: \{ft\} \par }
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}} {\colortbl ;\red0\green0\blue0;} \viewkind4\uc1\pard\qc\cf1\f0\fs16 File: \{f\} \par }
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}} {\colortbl ;\red0\green0\blue0;} \viewkind4\uc1\pard\qr\cf1\f0\fs16 Page: \{n\} of \{nn\} \par }

Solving Linear Ordinary Differential Equations

The function $subst f V p$ is a generaly utility function, for symbolic evaluation only, that will take an expression $f$ as the first argument and a vector $V$ of names in as the second argument and replace references to those names with subscripted references to the name given in the third argument $p$ .

Created: Luc Meekes, 2020-10-14 for Mathcad 15

$subst f V p n rows V n 0 n 0 f f substitute V p f n 1 V V n rows V j 0 j n f f substitute V j P j j j 1 f f substitute P p f$

The function $GetODEcoeffs ODE y t$ analyzes the Ordinary Differential Equation provided as the first parameter $ODE$ and extracts the coefficients of each of the derivatives of the function sought, the name of which is given as the second parameter $y$ . The independent variable is provided as the last parameter $t$ . The function returns the vector of coefficients.

$GetODEcoeffs ODE y t ODE_ subst subst ODE t t_ y y_ n last ODE_ laplace t_ s_ substitute laplace y_ t_ t_ s_ L_ coeffs s_ P ODE_ coeffs y_ t_ ORIGIN 1 P 0 i 1 n P stack P ODE_ coeffs t_ y_ t_ i ORIGIN 1 P stack P 0 Pok t_ P 0 substitute t_ 1.23456789 Pok P error Must be ODE with constant coefficients.$

The same function for an ODE containing multiple sought functions named in vector $y$ . The function returns a matrix with each column conatining the coefficients for each subsequent sought function.

$GetODEScoeffs ODE y t ODE_ subst ODE t t_ y_ L_ yt_ lyt_ y0_ y1_ y2_ y3_ y4_ y5_ y6_ y7_ y8_ y9_ L0_ L1_ L2_ L3_ L4_ L5_ L6_ L7_ L8_ L9_ y0_ t_ y1_ t_ y2_ t_ y3_ t_ y4_ t_ y5_ t_ y6_ t_ y7_ t_ y8_ t_ y9_ t_ laplace y0_ t_ t_ s_ laplace y1_ t_ t_ s_ laplace y2_ t_ t_ s_ laplace y3_ t_ t_ s_ laplace y4_ t_ t_ s_ laplace y5_ t_ t_ s_ laplace y6_ t_ t_ s_ laplace y7_ t_ t_ s_ laplace y8_ t_ t_ s_ laplace y9_ t_ t_ s_ i ORIGIN last y ODE_ subst ODE_ y i y_ i Lap ODE_ laplace t_ s_ i ORIGIN last y Lap Lap substitute lyt_ i L_ i n last Lap coeffs s_ j ORIGIN last y P ORIGIN j ODE_ coeffs yt_ j ORIGIN 1 P ORIGIN j 0 i ORIGIN 1 ORIGIN n P i j ODE_ coeffs t_ yt_ j i ORIGIN 1 P i j 0 Pok Ps 0 i ORIGIN ORIGIN n 1 Ps Ps t_ P i Ps 0 substitute t_ 1.23456789 Pok P error Must be ODE with constant coefficients.$

The function $LaplaceOfODElhs p y0 u Ly$ is a generaly utility function, for symbolic evaluation of linear ordinary differential equations, that will take a vector $p$ with coefficients belonging i'th order differentials of a function, a vector $y0$ with initial conditions, a parameter $u$ that specifies the independent variable for the Laplace domain and a parameter $Y$ to specify the Laplace transform of the function and produces the Laplace transform of the (homogenous part of the) differential equation.

$LaplaceOfODElhs p y0 u Y i p i u i ORIGIN Y k u i k y0 k 1 k i ORIGIN 1 last p ORIGIN last p$

The function $LODE1solve ode f y0 y t$ symbolically solves a (single) linear ordinary differential equation for which the lefthand segment (the part with the derivatives) is given by first parameter $ode$ , the righ hand segment ( inhomogenous part or particular function) is specified through function $f$ , the initial conditions are specfied in vector $y0$ , the sought function is specified through $y$ and the independent variable is specfied through the last parameter $t$ .

$LODE1solve ode f y0 y t y0 stack y0 0 p_ GetODEcoeffs ode y t last y0 last p_ y0 stack y0 0 A LaplaceOfODElhs p_ y0 s_ L_ C subst f t t_ laplace t_ s_ B A C simplify solve L_ B invlaplace s_ t$

The function $IsVector V$ checks if its parameter $V$ is a Vector. It works both numerically (as long as $V$ is numerically defined) but more importantly, it works symbolically.

$IsVector V rows V 1 0$

The function $LODEsolve ode f y0 y t$ symbolically solves a (set of) linear ordinary differential equation(s) for which the lefthand segment (the part with the derivatives) is given by first parameter (or vector) $ode$ , the righ hand segment ( inhomogenous part or particular function) is specified through function(s vector) $f$ , the initial conditions are specfied in vector (or matrix) $y0$ , the sought function(s) are specified through (vector) $y$ and the independent variable is specfied through the last parameter $t$ .

$LODEsolve ode f y0 y t n rows ode n 0 n 0 y0 stack y0 0 p_ GetODEcoeffs ode y t last y0 last p_ y0 stack y0 0 A LaplaceOfODElhs p_ y0 s_ L_ C subst f t t_ laplace t_ s_ B A C simplify solve L_ B invlaplace s_ t mp 1 i ORIGIN last ode p_ i GetODEScoeffs ode i y t mp max mp rows p_ i c cols y0 y0 ORIGIN y0 cols y0 n y0 augment y0 y0 0 rows y0 mp y0 stack y0 y0 0 rows y0 mp y0 ORIGIN mp 1 ORIGIN n 1 0 fn rows f fn 0 fn n f stack f 0 fn fn 1 L_ L0_ L1_ L2_ L3_ L4_ L5_ L6_ L7_ L8_ L9_ i ORIGIN last ode O i subst f i t t_ laplace t_ s_ j ORIGIN last ode O i O i LaplaceOfODElhs p_ i j y0 j s_ L_ j Sy_ submatrix L_ ORIGIN last y ORIGIN ORIGIN S O solve Sy_ i ORIGIN last ode R i S ORIGIN i invlaplace s_ t R$

By including this Mathcad sheet as a reference into another sheet, it is possible to solve (single, or sets of) L inear O rdinary D ifferential E quations with constant coefficients.

Note that an include sheet exists for Mathcad 11 (LODEsolve.mcd) separately from Mathcad 15 (LODEsolve.xmcd). The Mathcad 11 sheet will not work in Mathcad 15.

The function $LODEsolve ode f y0 y t$ symbolically solves a (set of) linear Ordinary Differential Equation(s) (ODE) with constant coefficients.

The parameters to the function are:

$ode$ S pecifies the left-hand segment of the ODE(s), the part with the sought function(s) and its derivatives .

Write this left-hand segment as you would write the right-hand side of a function definition.
You cannot use prime notation (
$y' t$ etc.), you must use $t y t$ and $t y t n$ to describe derivatives.

Note that de ODE(s) must be Linear, $LODEsolve$ cannot produce a correct solution if:
- powers of derivatives are included

- the coefficients of the derivatives depend on the independent variable (the last parameter to $LODEsolve$ ) .

$f$ Specifies the right hand segment of the ODE(s), the inhomogeneous part(s) or particular function(s) .

The function(s) should be (a) mathematical function(s) for which the Laplace transform exists.

For for homogenous ODE(s), those with out particular function(s), supply a $0$ .

$y0$ A vector (or matrix) with the initial conditions of the function(s) and its (their) derivatives.

In general for each function you must supply a number of initial conditions that is
one less than the highest derivative that occurs for that function. Pad with $0$ 's if necessary.

You cannot specify an initial condition for a value of the independent parameter other than $0$ .

See examples on how to deal with that situation.

LODEsolve will enlarge the vector (or matrix) with 0's for any initial condition not provided.

$y$ The name of t he sought function, or a vector of names in case of an ODE set, you can use any name (see notes below).

You MUST use the name(s) you give here as the name for the function(s) in $ode$ .

$t$ The name of the independent variable, you can use any name (see notes below) .

You MUST use the name you give here as the name for the independent variable in $ode$ and in $f$ .

Notes:The function $LODEsolve$ is a symbolic only function. This means that you cannot evaluate it numerically.
But you can assign its result to a function and use that numerically.

There are limits to the order of the ODE that can be solved. Symbolic solutions exist for polynomials up to order 4.

If the span of derivatives exceeds 3, it is well possible that no solution will be found.
For a set of ODE, derivatives up to the 9
th can be handled (of course, without guarantee that a solution will be found).

Since LODEsolve is a symbolic function, you can use it to solve fully symbolic ODE's fully symbolically.

You should not use names that end in _\$. Such names are used internally, and may cause unexpected results.