Tuesday, July 6, 2010

Generate Smith chart on the computer with linSmith

I studied Electrical Engineering at West Negros College but I can't recall using a Smith chart for transmission line calculations and other uses. Instead we use our slide rules and the just coming of age Casio fx-102 (with micro fluorescent glow tubes) or a TI-58 for some lucky classmates, for computing directly the equations involving hyperbolic functions.

Nevertheless, in this modern era, a Smith Chart is still a very useful graphics method for getting a quick grasp of the effects of system design parameters on constant or varying frequency. In this entry we concentrate on linSmith a FREE software for drawing Smith Chart and diagrams superimposed on it by the program. I mean, you don' have to manually plot points on the chart itself, the program will do it for you. Luckily the linSmith program is comprehensive and comes with usefule examples for self study. You can always do self-education after you graduate!

Here is a description from the Ubuntu package which is at version 0.99.7-1,

  • Definition of multiple load impedances (at different frequencies)
  • Addition of discrete (L, C, parallel and series LC, and transformer)
    and line components (open and closed stubs, line segments)
  • Connection in series and parallel
  • Easy experimentation with values using scrollbars
  • A 'virtual' component switches from impedance to admittance to help
    explaining (or understanding) parallel components
  • The chart works in real impedances (not normalized ones)
  • Direct view of the result on the screen
  • Ability to generate publication quality Postscript output
  • A 'log' file with textual results at each intermediate step
  • Load and circuit configuration is stored separately, permitting several
    solutions without re-defining the other



Ubuntu puts the LinSmith package in the desktop menu at Applications/Other/ (together with gretl, Geomview, and Snappea.Here is a pic of the software:



linSmith has a developer homepage at John Coppens. The developer even recommends you compile from the latest sources! The latest version is already at 0.99.12 making the Ubuntu package out of date.
An Introduction and tutorial are also available from the homepagepage.

Wikipedia has an entry on Smith Chart.

We will hopefully write articles on problemsolving with linsmith in the future, as one of our aims is to present an engineering review in our blogs.

Sunday, July 4, 2010

LyX: A high level gui Latex frontend and document processor

We have described Kile in an earlier post in this blog, and it is a simple, well thought of assemblage of and interactive editor and tools for creating and viewing output of correct Latex source.

Is there a more high level gui for Latex? One which shows superscripts, subscripts in their natural positions and able to help the Latex writer form tables and equations? and even create bibliographies and cross references easily?

Well Lyx is just that tool. Now at 1.6.5 in Ubuntu, Lyx does not leave its users helpless in using its powerful capabilities. The software comes with an introduction, tutorial and even a users's guide all accessible from the graphical menu!


Lyx shows what an equation will look in print right inside the editor! For example, look at the image below.


Instead of just typing $ax^2 + bx + c = 0$ and imagining what it will look like in the output dvi/ps/pdf output, Lyx above shows you how it will look like right inside the editing screen!
Never has a latex processing been made easier and in fact Lyx has found favor by book writers,
who has learned a little latex. The graphical aids can help a newbie to create a typeset formula, much more beautiful than in and openoffice of MS word document.

We will start writing more on LyX, in the near future, stay tuned!

Lazarus: A Free Delphi for Linux!

Those were the days of rampant piracy, of using Turbo Pascal 2.1 to Delphi to Borland C++ Builder, for our programming projects. Later my heart jumped for joy when Kylix was introduced for Linux but that was a shortlived affair! The Kylix project died but the open source project Lazarus woke up Pascal from the dead and delivered a slick high quality sophisticated emulation of Delphi for Linux!

Lazarus is sure to bring smiles to delphi developers. It gives a graphical IDE for the Free Pascal Compiler. The output is a Linux executable in native (not interpreted) code!

Here is a snapshot. You must run lazarus ide from the graphical Applications menu not from the terminal or console.


When it opens, 4 windows are active: Lazarus Ide, source editor,Form1, object inspector and messages. Lazarus faithfully follows the delphi look and feel and we wonder if Borland or its successor approves of the copying.

We have done our PhD computing projects using a pirated copy of Delphi. Now I am not embarassed to use a clean copy in Linux. More power to the Lazarus developers and we hope to start writing more articles on Lazarus.

The version of Lazarus installed is 0.9.28, while the FPC compiler is at version 2.4.0. Don't laugh at the FPC compiler, it is one of the best compilers for creating ultra fast Linux binaries!

We will restart our Pascal love in the near future. Stay tuned for small projects using Lazarus.

Gambas, a free Visualbasic-like fast IDE on Linux!


Recent developments in Linux points out to the power of a community of inspired developers working  to produce and maintain quick IDEs to produce software. Here is one Visuabasic like environment which may give smiles to Linux users. It is exotically named Gambas (Gambas means almost basic like) and it is even already at version 2!
This may give a high quality tool to Linux software developers who are already familiar with the productivity and time efficiency of Delphi, C++Builder, and Visualbasic developers in Windows.

Gambas is easily installed using apt-get or synaptic tool in LInux. You will be presented with an operning screen shown above. Explore the power of Gamas by clicking on the examples.Choosing Timer for example and attempting to run it result in a displayed error box saying "Cannot load class 'Ftimer'. Unable to load class file. It turns out that the examples subdirectory is read only! So do the following:

sudo chmod -R o+w /usr/share/gambas2/examples

and all examples will run fine! Here is a snapshot of the timer example.



Now one can borrow or buy any Visual basic book and start creating fantastic graphical applications!
We just focus first on the installation. Then later we will write blog articles with examples for Gambas.

Saturday, July 3, 2010

qtOctave, another matlab-like computational software, free!

You will find qtoctave in the standard Ubuntu software repositories. And a simple
sudo apt-get install qtoctave will install the software with the need dependencies, all automatically! Life is simple with Linux. Sorry, but I hesitate in showing you how to install in Windows since I don't have a machine with the virus friendly OS around.

Of course, you can run Octave from the primitive looking command line, but why suffer? QtOctave gives you both Octave with an eyecandy Qt gui, making you more productive and wont make you look like a dinosaur when in a room full of Windows or even Mac users.

When you click on qtOctave in Applications/Science/qtOctave in a Gnome desktop, you will be presented with the following screen (with Help/Octave help enabled). qtOctave gave me an opening message that it requires an Octave 3.2.0 version. The Ubuntu version I have is 3.0.5, so hopefully the Ubuntu maintainers will give an update soon! QtOctave itself is at version 0.8.2.


The current version of Octave does not evaluate the expression exp(e * pi) in the terminal window.Will need to download the latest version of Octave!

The home page of Octave is Octave home page

Will come back in a week or two. Stay tuned.

July 4, 2010: I have downloaded the latest stable Octave 3.2.4, but the make process is taking a long time, even with a dual core machine.

-lX11  -lreadline  -lncurses -ldl -lhdf5 -lz -lm  -lfreetype -lz -L/usr/X11R6/lib -lGL -lGLU 
../libcruft/libcruft.so: undefined reference to `r_imag'
../libcruft/libcruft.so: undefined reference to `c_exp'
../libcruft/libcruft.so: undefined reference to `i_len'
../libcruft/libcruft.so: undefined reference to `d_int'
../libcruft/libcruft.so: undefined reference to `c_sqrt'
../libcruft/libcruft.so: undefined reference to `e_wsfi'
../libcruft/libcruft.so: undefined reference to `d_sign'
../libcruft/libcruft.so: undefined reference to `s_wsle'
../libcruft/libcruft.so: undefined reference to `r_mod'
../libcruft/libcruft.so: undefined reference to `c_div'
../libcruft/libcruft.so: undefined reference to `r_cnjg'
../libcruft/libcruft.so: undefined reference to `s_copy'
../libcruft/libcruft.so: undefined reference to `s_cmp'
../src/liboctinterp.so: undefined reference to `s_wsfe'
../libcruft/libcruft.so: undefined reference to `do_lio'
../libcruft/libcruft.so: undefined reference to `c_log'
../libcruft/libcruft.so: undefined reference to `r_int'
../libcruft/libcruft.so: undefined reference to `pow_dd'
../libcruft/libcruft.so: undefined reference to `i_indx'
../libcruft/libcruft.so: undefined reference to `s_wsfi'
../libcruft/libcruft.so: undefined reference to `z_abs'
../libcruft/libcruft.so: undefined reference to `s_stop'
../libcruft/libcruft.so: undefined reference to `r_sign'
../libcruft/libcruft.so: undefined reference to `pow_di'
../libcruft/libcruft.so: undefined reference to `d_lg10'
../libcruft/libcruft.so: undefined reference to `pow_ri'
../libcruft/libcruft.so: undefined reference to `e_wsle'
../libcruft/libcruft.so: undefined reference to `s_cat'
../src/liboctinterp.so: undefined reference to `do_fio'
../src/liboctinterp.so: undefined reference to `e_wsfe'
../libcruft/libcruft.so: undefined reference to `c_abs'
../libcruft/libcruft.so: undefined reference to `d_mod'
collect2: ld returned 1 exit status
make[2]: *** [octave] Error 1
make[2]: Leaving directory `/home/toto/Downloads/octave-3.2.4/src'
make[1]: *** [src] Error 2
make[1]: Leaving directory `/home/toto/Downloads/octave-3.2.4'
make: *** [all] Error 2

Nuts! So we have no choice but to wait for the Ubuntu version??!!

July 4: We removed qtOctave and old versions of Octave via Synaptic,
choosing the latest 3.2 series for Octave.
When we reinstalled qtOctave the terminal now works. For example:

>>> exp(i * pi)
ans = -1.0000e+00 + 1.2246e-16i
>>> sqrt(-1)
ans =  0 + 1i

Now that it runs, we will have impetus to write future articles for octave, the poor man's
matlab-like clone.

Scilab, a matlab-like environment, only it is free!

Scilab is a free (with compatible GPL license) Matlab like software for interactive numerical computation developed by French academics/programmers at INRIA. It has been developed through the years and has acquired sophisticated libraries for various applications, such as optimization, linear algebra, parallel computing, signal processing, simulation and other fields. If you cannot afford MATLAB, then your can afford Scilab. Scilab competes with R, Octave, Euler,Python-Scipy/Scientific, but if you do choose Scilab for your applied mathematics research work, Scilab will not disappoint. The wealth of free tools may make the user dizzy what to choose, in fact, one may resort to a hybrid approach using one or more of the available tools. As if to emphasize the enriched environment, Scilab has interfaces to computational codes in scientific libraries written in various languages such as fortran and C/C++. If you want the cheapest, fastest in implementing a comutational algorithm form conception to implementation and production stage, Scilab might win easily.

Scilab is hosted at Scilab homepage. All documentation, sources, libraries may be found there for quick downloads.

Scilab has a gui-console. Here are some examples. Scilab might take some time to initialize when it is invoked from the command line or graphical shell. Here is what you may see:


If you are very new to Scilab, the easiest way to feel at ease is to let Scilab demonstrate to you what it can do. Click on ?/Scilab Demonstrations. Select introduction. And Scilab will give you a basic tutorial! Press ENTER key to continue.Here is a snapshot of a Scilab introduction session:

 >>//               SCILAB OBJECTS
>>//               SCILAB OBJECTS
>>//               1. SCALARS
>>a=1               //real constant
 a  =
 
    1.  
>>1==1              //boolean
 ans  =
 
  T  

-->
>>'string'          //character string
 ans  =
 
 string   
>>
>>z=poly(0,'z')     // polynomial with variable 'z' and with one root at zero
 z  =
 
    z   
>>
>>p=1+3*z+4.5*z^2   //polynomial 
 p  =
 
                 2  
    1 + 3z + 4.5z   >>r=z/p             //rational
 r  =
 
          z         
    -------------   
                 2  
    1 + 3z + 4.5z   
>>//                2. MATRICES
>>A=[a+1 2 3
>>     0 0 atan(1)
>>     5 9 -1]      //3 x 3 constant matrix
 A  =
 
    2.    2.    3.         
    0.    0.    0.7853982  
    5.    9.  - 1.         
>>b=[%t,%f]         //1 x 2 boolean matrix
 b  =
 
  T F  
>>Mc=['this','is';
>>    'a' ,'matrix']   //2 x 2 matrix of strings
 Mc  =
 
!this  is      !
!              !
!a     matrix  !
>>Mp=[p,1-z;
>>    1,z*p]        //2 x 2 polynomial matrix
 Mp  =
 
                 2                    
    1 + 3z + 4.5z     1 - z           
                                      
                            2      3  
    1                 z + 3z + 4.5z   
>>F=Mp/poly([1+%i 1-%i 1],'z')   //rational matrix
 F  =
 
                  2                       
     1 + 3z + 4.5z        - 1             
    ---------------     ---------         
               2   3              2       
  - 2 + 4z - 3z + z     2 - 2z + z        
                                          
                               2      3   
           1             z + 3z + 4.5z    
   ---------------     ---------------   
               2   3               2   3  
  - 2 + 4z - 3z + z   - 2 + 4z - 3z + z   
>>Sp=sparse([1,2;4,5;3,10],[1,2,3])   //sparse matrix
 Sp  =
 
(    4,   10) sparse matrix
 
(    1,    2)        1. 
(    3,   10)        3. 
(    4,    5)        2. 
>>Sp(1,10)==Sp(1,1)                   //boolean sparse matrix
 ans  =
 
(    1,    1) sparse matrix
 
(    1,    1)    T 
>>//                 3. LISTS
>>L=list(a,-(1:5), Mp,['this','is';'a','list'])   //list
 L  =
 
 
       L(1)
 
    1.  
 
       L(2)
 
  - 1.  - 2.  - 3.  - 4.  - 5.  
 
[Continue display? n (no) to stop, any other key to continue]

We encourage the reader to install scilab using your package installer in Linux. The version I have
is 5.2.1. Scilab is also available for MS Windows.

We will present some tools-libraries available in Scilab in the future. Stay tuned.

Rev. Jul 15: Another optimization library with Python interface: NLopt, installation problem



NLopt is a free/open-source library for nonlinear optimization, providing a common interface for a number of different free optimization routines available online as well as original implementations of various other algorithms. Its features include (from the home page of NLopt):

  • Callable from C, C++, Fortran, GNU Octave, Matlab, Python, and GNU Guile.
  • A common interface for many different algorithms—try a different algorithm just by changing one parameter.
  • Support for large-scale optimization (some algorithms scalable to millions of parameters and thousands of constraints).
  • Both global and local optimization algorithms.
  • Algorithms using function values only (derivative-free) and also algorithms exploiting user-supplied gradients.
  • Algorithms for unconstrained optimization, bound-constrained optimization, and general nonlinear inequality/equality constraints.
  • Free/open-source software under the GNU LGPL (and looser licenses for some portions of NLopt).
The homepage of NLopt is at NLopt homepage and the web site is fairly complete with FAQ, Download, Manual, Tutorial, Reference , Algorithms, License and copyright pages. Instructions for installation.
  1. Download the installer file

    wget -ct 0 http://ab-initio.mit.edu/nlopt/nlopt-2.0.2.tar.gz

  2. Unpack the nlopt-2.0.2.tar.gz.

    tar xzvvf nlopt-2.0.2.tar.gz

  3. Cd to the nlopt directory.
    cd nlopt-2.0.2.

  4. Perform standard installation commands. Type ./configure -h for help.

    ./configure --enable-shared
    make;
    sudo make install


  5. Make links to the shared libraries.
    sudo ldconfig



Unfortunately in the last step, we encounter
/bin/bash ../libtool --tag=CXX   --mode=link g++  -g -O2 -module 
-no-undefined -version-info 3:2:3  -o _nlopt.la -rpath /usr/local/lib/python2.6/dist-packages _nlopt_la-nlopt-python.lo ../libnlopt.la -lm 
libtool: link: g++ -shared -nostdlib /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbeginS.o  .libs/_nlopt_la-nlopt-python.o   ../.libs/libnlopt.a -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../.. -L/usr/lib/x86_64-linux-gnu -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crtn.o    -Wl,-soname -Wl,_nlopt.so.0 -o .libs/_nlopt.so.0.3.2
/usr/bin/ld: ../.libs/libnlopt.a(general.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
../.libs/libnlopt.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [_nlopt.la] Error 1
make[2]: Leaving directory `/home/toto/Downloads/nlopt-2.0.2/swig'
make[1]: *** [install] Error 2
make[1]: Leaving directory `/home/toto/Downloads/nlopt-2.0.2/swig'
make: *** [install-recursive] Error 1
The error message says we have to recompile with -fPIC flag. A show stopper! Have to review how to insert the compiler flag in the configure file. Will be back this week. Interfacing with Python requires that Numpy is installed. Nevertheless, a Python example is


import nlopt
from numpy import *

def myfunc(x, grad):
    if grad.size > 0:
        grad[0] = 0.0
        grad[1] = 0.5 / sqrt(x[1])
    return sqrt(x[1])

def myconstraint(x, grad, a, b):
    if grad.size > 0:
        grad[0] = 3 * a * (a*x[0] + b)**2
        grad[1] = -1.0
    return (a*x[0] + b)**3 - x[1]

opt = nlopt.opt(nlopt.LD_MMA, 2)
opt.set_lower_bounds([-float('inf'), 0])
opt.set_min_objective(myfunc)
opt.add_inequality_constraint(lambda x,grad: myconstraint(x,grad,2,0), 1e-8)
opt.add_inequality_constraint(lambda x,grad: myconstraint(x,grad,-1,1), 1e-8)
opt.set_xtol_rel(1e-4)

x = opt.optimize([1.234, 5.678])
minf = opt.last_optimum_value()
print "optimum at ", x[0],x[1]
print "minimum value = ", minf
print "result code = ", opt.last_optimize_result()


We would like to compare its performance with OpenOpt which was describe earlier in this blogs.

July 15


Cleaning up previous installation as per suggestion and running the example, we get


python example.py
optimum at 0.333333612374 0.296296070953
minimum value = 0.544330846961
result code = 4


We have to delve deeper into nlopt documentation to understand the various result codes.
We feel that optimization software with the best comprehensive documentation (no suprise principle)
will find wider use. We will try to play with nlopt in the coming days. Stay tuned.

Thanks to the comments from the head of the NLOPT development team.