Tuesday, December 4, 2012

Using GNU Octave to solve symbolic Equations


GiNaC is the Symbolic package for GNU Octave


I have been trying to move completely to use GNU Octave instead of using Matlab.  Matlab is a high-level programming language for working with matrices and is very widely used now by Engineers and other fields for calculations and analyses.  The issue is Matlab is very expensive package to own and not everyone can install it on his/her personal computer.  Moreover, now that I use Ubuntu Linux as my main OS, Hello to the Free world and goodbye to other OS ties and limitations, I can not run Matlab anyway on Ubuntu.
So, I use GNU Octave to perform all my calculations and code algorithms I need.  I just realized that I need to do some symbolic calculations and I know what I need to do that in Matlab
    syms x
or
    x =  
sym("x")
and that is enough for what I need.  I come to find out that it does not work for GNU Octave.  So, to make the long story short , here is what you need to do to get that working
when installing GNU Octave I used this command
    sudo apt-get install octave3.2 octave3.2-common octave3.2-doc octave3.2-dbg
This will install all what you need to install Octave.  but you still missing one package
    sudo apt-get install octave-symbolic
This is the package that contains GiNaC support for symbolics.

Here is a simple example to show you how to use it in GNU Octave:

% This is an example to show you how to calculate total value to two resistors in parallel
octave-3.2.3:1> symbols        % Initialize symbolic manipulation
octave-3.2.3:2> R1 = sym("r1")
R1 =

r1
octave-3.2.3:3> R2 = sym("r2")
R2 =

r2
octave-3.2.3:13> Z = (R1 * R2)/(R1 + R2)
Z =

(r2+r1)^(-1)*r2*r1
octave-3.2.3:14> subs(Z, {R1, R2}, {10,10})  % substitute the R1, R2 values with 10 Ohms each
ans =

5.0

Please, Leave me comments or opinions about what you think, Thanks,

No comments:

Post a Comment