Saturday, May 20, 2023

Casio Classpad fx-CP400: Solving a System of Linear Differential Equations Using Laplace Transforms

Casio Classpad fx-CP400: Solving a System of Linear Differential Equations Using Laplace Transforms



Introduction


The following procedure should work with the Casio Classpad family of calculators (300, 330, fx-CP400, fx-CP500). 


An attempt to use the Casio Classpad to solve the system of differential equations:


dxf/dt = A * xf(t) + B * yf(t) + g1(t)

dyf/dt = C * xf(t) + D * yf(t) + g2(t)


Initial conditions:  xf(0) = xf0,   yf(0) = yf0



The independent variable in all the functions is t.  The Casio Classpad's CAS functions laplace and invLaplace are used to accomplish this task.



Syntax


Laplace Transform of f(t):


laplace(f(t), t, s)


Laplace Transform of a Differential Equation:


laplace(diff eq, independent variable, dependent variable, s)


Inverse Laplace Transformation:


invLaplace(ℒ(s), s, t)


t:  parameter of the original function f(t)

s:  parameter of the transformed function ℒ(s)


The definition of a Laplace Transformation:


ℒ(f(t))(s) = ∫( f(t) * e^(-s*t) dt, t = 0 to ∞)


Now, even though we are working a system of differential equations, the laplace and invLapace commands can only work on function at a time.  Any other variable will be treated as a constant, even it was meant to represent another functions.  The substitution steps will account for this.  


The variables used to respect the Classpad's system variables.  


Here are the steps I used to solve:


dxf/dt = A * xf(t) + B * yf(t) + g1(t)

dyf/dt = C * xf(t) + D * yf(t) + g2(t)


Initial conditions:  xf(0) = xf0,   yf(0) = yf0


Spaces are added to readability.  



1.  Store dxf/dt in the variable f1.   Use xf' to represent dxf/dt.  


2.  Store dyf/dt in the variable f2.   Use yf' to represent dyf/dt.


3.  Execute the following and substitutions:


laplace( f1, t, xf, s ) ⇒ g1

g1 | xf(0) = xf0 and  yf / s = Mp ⇒ g1


4.  Execute the following and substitutions:


laplace( f2, t, yf, s ) ⇒ g2

g2 | yf(0) = yf0 and Lp = Mp ⇒ g2

g2 | xf /s = Lp ⇒ g2


Note Lp = ℒ( xf(t) ) and Mp = ℒ( yf(t) )


5.  Now solve the system of transformed equations: 


solve( {g1, g2}, {Lp, Mp} ) ⇒ lists


6.  Take the inverse laplace transforms:


invLaplace( getRight( lists[1], s, t ) ) ⇒ h1

invLaplace( getRight( lists[2], s, t ) ) ⇒ h2


The solutions are:


xf(t) = h1

yf(t) = h2


The getRight command extracts the right side of an equation.



Examples


Example 1:


xf ' = -0.08 * xf + 0.02 * yf + 6

yf ' = 0.08 * xf - 0.08 * yf


Initial conditions:  xf(0) = 0, yf(0) = 150






Example 2:


xf ' = 2 * xf + yf + t^2

yf ' = -2 * xf + 5


Initial conditions:  xf(0) = 2, yf(0) = 5




Casio Classpad Program:  laplaced


Download here:  https://drive.google.com/file/d/1zxTEynCjXmBrPU9pYqmXo3kF_so7fiI-/view?usp=share_link


Code:


' setup

SetRadian


' local variables

Local str1, str2, f1, f2

Local g1, g2, lists, h1, h2

Local Mp, Lp, t, s, xval, yval


' main

ClrText

InputStr str1, "xf'(xf,yf,g1(t))="

InputStr str2, "yf'(xf,yf,g2(t))="

Input xval, "xf(0)? "

Input yval, "yf(0)? "


StrJoin "xf'=", str1, str1

StrJoin "yf'=", str2, str2

strToExp(str1) ⇒ f1

strToExp(str2) ⇒ f2


' transform and solve

laplace(f1, t, xf, s) ⇒ g1

g1 | xf(0) = xval and yf/s = Mp ⇒ g1


laplace(f2, t, yf, s) ⇒ g2

g2 | yf(0) = yval and Lp = Mp ⇒ g2

g2 | xf/s = Lp ⇒ g2


Print "Laplace Transforms:"

PrintNatural g1

Print g1

PrintNatural g2

Print g2


solve({g1, g2},{Lp, Mp})⇒lists

invLaplace(getRight(lists[1]),s,t) ⇒ h1

invLaplace(getRight(lists[2],s,t) ⇒ h2


Print "Solutions: "

Print "xf = "

PrintNatural h1

Print h1

Print "yf = "

PrintNatural h2

Print h2


Note:  PrintNatural displays the expression in textbook form in a popup box, but it does not add anything to the text output terminal.  This is why I included both PrintNatural and Print commands.  



Source


Kreyszig, Erwin.  Advanced Engineering Mathematics  8th Edition  John Wiley & Sons, Inc:  New York, NY.  1999.  ISBN 0-471-15496-2



All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.