Friday, April 8, 2016

Setting up Octave environment to calculate laplace() and ilaplace()

I recently encountered an issue trying to calculate the laplace() and inverse laplace() transforms using Octave. Here are the set of steps that I used to set up support for these functions in octave:

My environment:

>> lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty

>> sudo aptitude install octave # install octave 
>> octave -version 
GNU Octave, version 3.8.1
Copyright (C) 2014 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.

Octave was configured for "x86_64-pc-linux-gnu".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.


>> sudo aptitude install liboctave-dev # install octave-dev libs 
>> sudo apt-get install python-setuptools
>> sudo easy_install pip
>> sudo pip install sympy
>> octave --force-gui # install octave in gui mode 

Octave should launch with the gui loaded: 


Run the following commands in Octave: 

Octave$>> pkg install -forge symbolic
This command should take a while to load and the following error message should be displayed 
For information about changes from previous versions of the symbolic package, run 'news symbolic'.

Octave$>> news symbolic # to test that symbolic is installed 



Octave$>> pkg load symbolic  # load symbolic package 

You should now be able to run laplace and inverse laplace transforms as shown in the screen shot below

Octave$>> syms t
>> f = t^2;
>> laplace(f)
ans = (sym)

  2
  ──
   3
  s

>> syms t s
>> f=-1.25+3.5*t*exp(-2*t)+1.25*exp(-2*t);
warning: Using rat() heuristics for double-precision input (is this what you wanted?)
warning: Using rat() heuristics for double-precision input (is this what you wanted?)
warning: Using rat() heuristics for double-precision input (is this what you wanted?)
>> F=laplace(f,t,s)
F = (sym)

       s - 5
  ────────────────
     ⎛ 2               ⎞
  s⋅⎝s  + 4⋅s + 4⎠

>> syms a s x
>> F = 1/(s - a)^2;
>> ilaplace(F, x)
ans = (sym)

     x⋅re(a)  ⅈ⋅x⋅im(a)
  x⋅ℯ       ⋅ℯ