jueves, 8 de marzo de 2012

Aproximación de Padé de tiempos muertos en Octave

Padé approximation of delays for GNU Octave


--- pade.m ---
## -*- texinfo -*-
## @deftypefn  {Function File} {} pade (@var{q})
## @deftypefnx {Function File} {} pade (@var{q}, @var{n})
##
## Calcula la aproximacion de Pade de orden @var{n} para exp(-q.s) (s = variable compleja),
## y devuelve una funcion de transferencia continua.
##
## @var{q} es un numero entero.
##
## @var{n} es el orden de la aproximacion de Pade. Si se omite se asume @samp{"1"}.
##
## La aproximacion se calcula segun (OZBAY, Hitay. Introduction to Feedback Control Theory. USA: CRC Press, 1999. 232 p. ISBN 0-8493-1867-X):
##
##    $\textrm{e}^{-\Theta\,t}\approxeq\dfrac{\sum_{k=0}^{n}\,(-1)^{k}\, c_{k}\,(\theta s)^{k}}{\sum_{k=0}^{n}\, c_{k}\,(\theta s)^{k}}$
##
##    donde: $c_{k}=\dfrac{(2n-k)!\, n!}{(2n)!\, k!\,(n-k)!}$
##
##    para $k=1,2,\ldots,n$
##
## @end deftypefn

## Author: Alejandro Regodesebes -
## v.1.0 - Copyright (C) 2012 Alejandro Regodesebes

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see .
 
function p = pade(q,n=1)
  if (not(isnumeric(q)))
    error("Los argumentos deben ser constantes enteras.");
  endif
  if (nargin == 0 || nargin > 2)
    print_usage ();
  endif
  s = tf("s"); % s es la variable de una función de transferencia
  Num = 0; % Inicializo el numerador
  Den = 0; % Inicializo el denominador
  nn = prod(1:n); % nn = n!
  n2 = prod(1:(2*n)); % n2 = (2n)!
  for k=0:n
    c = (prod(1:(2*n-k))*nn)/(n2*prod(1:k)*prod(1:(n-k)));
    Num = Num + ((-1)**k)*c*(q*s)**k;
    Den = Den + c*(q*s)**k;
  end;
  p = Num/Den;
endfunction
--- fin pade.m ---

miércoles, 7 de marzo de 2012

Transformada y transformada inversa de Laplace en Octave

Symbolic transform and inverse Laplace transform in Octave.
Los dos scripts que siguen utilizan GNU Maxima para calcular la transformada y la transformada inversa de Laplace desde Octave. El resultado es un string que puede ser convertido y utilizado en Octave.

The next two scripts uses GNU Maxima for calculate symbolic transform and inverse Laplace transform from Octave. The result is a string that can be converted and used in Octave.

--- laplace.m ---
## -*- texinfo -*-
## @deftypefn  {Function File} {} laplace (@var{funcion})
## @deftypefnx {Function File} {} laplace (@var{funcion}, @var{t})
## @deftypefnx {Function File} {} laplace (@var{funcion}, @var{t}, @var{s})
##
## Utiliza GNU-Maxima para calcular la transformada de Laplace del string @var{funcion}.
## La salida es un string con la funcion transformada.
## GNU-Maxima puede encontrarse en http://maxima.sourceforge.net/
##
## @var{t} es la variable de la funcion @var{funcion}, si se omite se asumira @samp{"t"}.
## @var{s} es la variable de la transformada, si se omite se asumira @samp{"s"}.
##
## Ejemplos:
##
## @example
## @group
## laplace ("sin(2*t)")
##    @result{} 2/(s^2+4)
## @end group
## @group
## laplace ("sin(2*x)","x")
##    @result{} 2/(s^2+4)
## @end group
## @group
## laplace ("sin(2*x)","x","r")
##    @result{} 2/(r^2+4)
## @end group
## @end example
##
##
## @seealso{ilaplace, maxima}
## @end deftypefn
##
##
## Ejemplo:
##
## @example
## @group
## s = tf ("s");
## @end group
## @group
## g = eval(laplace ("sin(2*t)"))
##
##    @result{} Transfer function 'g' from input 'u1' to output ...
##
##    @result{}          2 
##    @result{}  y1:  -------
##    @result{}       s^2 + 4
##
##    @result{} Continuous-time model.
## @end group
## @end example

## Author: Alejandro Regodesebes -
## v.1.0 - Copyright (C) 2012 Alejandro Regodesebes

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see .

function resultado = laplace(comando,t="t",s="s")
    if (not(ischar(t)))
        error("El segundo argumento debe ser un string con la variable de la función a transformar.");
    endif
    if (not(ischar(s)))
        error("El tercer argumento debe ser un string con la variable de la función transformada.");
    endif
    if (nargin == 0 || nargin > 3)
        print_usage ();
        error("Cantidad de argumentos incorrecta.");
    endif
    if (ischar(comando))
        comando = strtrim(comando);
        [nn,salida] = system(['maxima -q --batch-string="display2d:false;laplace(',comando,',',t,',',s,');"']);
        resultado = strtrim(substr(salida,rindex(salida,"(%o")+5));
        resultado(resultado == "%") = "";
    else
        printf("ERROR: el argumento debe ser un string\n");
        print_usage ();
    endif
endfunction
--- fin laplace.m ---

--- ilaplace.m ---
## -*- texinfo -*-
## @deftypefn  {Function File} {} ilaplace (@var{funcion})
## @deftypefnx {Function File} {} ilaplace (@var{funcion}, @var{s})
## @deftypefnx {Function File} {} ilaplace (@var{funcion}, @var{s}, @var{t})
##
## Utiliza GNU-Maxima para calcular la transformada inversa de Laplace del string @var{funcion}.
## La salida es un string con la funcion transformada inversa.
## GNU-Maxima puede encontrarse en http://maxima.sourceforge.net/
##
## @var{s} es la variable de la funcion @var{funcion}, si se omite se asumira @samp{"s"}.
## @var{t} es la variable de la transformada inversa, si se omite se asumira @samp{"t"}.
##
## Ejemplos:
##
## @example
## @group
## ilaplace("10/(s^2+2*s+5)")
##    @result{} 5*e^-t*sin(2*t)
## @end group
## @group
## ilaplace("10/(f^2+2*f+5)","f")
##    @result{} 5*e^-t*sin(2*t)
## @end group
## @group
## ilaplace("10/(f^2+2*f+5)","f","x")
##    @result{} 5*e^-x*sin(2*x)
## @end group
## @end example
##
##
## @seealso{laplace, maxima}
## @end deftypefn

## Author: Alejandro Regodesebes -
## v.1.0 - Copyright (C) 2012 Alejandro Regodesebes

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see .

function resultado = ilaplace(comando,s="s",t="t")
    if (not(ischar(s)))
        error("El segundo argumento debe ser un string con la variable de la función transformada.");
    endif
    if (not(ischar(t)))
        error("El tercer argumento debe ser un string con la variable de la función transformada inversa.");
    endif
    if (nargin == 0 || nargin > 3)
        print_usage ();
        error("Cantidad de argumentos incorrecta.");
    endif
    if (ischar(comando))
        comando = strtrim(comando);
        [nn,salida] = system(['maxima -q --batch-string="display2d:false;ilt(',comando,',',s,',',t,');"']);
        resultado = strtrim(substr(salida,rindex(salida,"(%o")+5));
        resultado(resultado == "%") = "";
    else
        printf("ERROR: el argumento debe ser un string\n");
        print_usage ();
    endif
endfunction

--- fin ilaplace.m ---

Llamar a Maxima desde Octave

Calling Maxima from Octave.

El siguiente script define una función en Octave que envía una lista de comandos a Maxima y devuelve un string con la última salida de Maxima.

No es muy elegante, y necesita algo de trabajo, pero cumple su función.

The following script defines a function in Octave that sends a list of commands to Maxima and returns a string with the last departure from Maxima.

It's not elegant, and needs some work, but it does its job.



--- maxima.m ---
## -*- texinfo -*-
## @deftypefn  {Function File} {} maxima (@var{comando})
##
## Ejecuta uno o mas comandos en GNU-Maxima y devuelve un string con el resultado del ultimo comando.
## GNU-Maxima puede encontrarse en http://maxima.sourceforge.net/
## Executes one or more commands in GNU-Maxima and returns a string containing the result of last command.
## GNU-Maxima can be found at http://maxima.sourceforge.net/
##
## @var{comando} es un string conteniendo el o los comandos a ejecutar en GNU-Maxima. Estos comandos deben separarse mediante @samp{";"}.
## @var{comando} is a string containing the command(s) to run on GNU-Maxima. These commands must be separated by @samp{";"}.
##
## Ejemplos/Examples:
##
## @example
## @group
## maxima("1+1;laplace(%,t,s)")
##    @result{} 2/s
## @end group
## @end example
##
##
## @seealso{ilaplace, maxima}
## @end deftypefn

## Author: Alejandro Regodesebes -
## v.1.0.1 - Copyright (C) 2012 Alejandro Regodesebes

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see .

function resultado = maxima (comando)
    if ((nargin == 1) && ischar(comando))
        comando = strtrim(comando);
        if (substr(comando, -1) != ";")
            comando = [comando,';'];
        endif
        #{ Llama a Maxima en modo silencioso (-q), para procesar por lotes una lista de argumentos (--batch-string="..."), y le envía como argumentos la orden de mostrar la salida en una sola línea (display2d:false;) más el comando deseado. La salida de Maxima se almacena en el string "salida":#}
        [nn,salida] = system(['maxima -q --batch-string="display2d:false;',comando,'"']);
        #{ Remueve los espacios al principio y al final (strtrim) de la parte del string "salida" (substr) que comienza 5 caracteres después (+5) del primer carácter de del último "(%o" (rindex):#}
        resultado = strtrim(substr(salida,rindex(salida,"(%o")+5));
        #{ Elimina todos los signos "%":#}
        resultado(resultado == "%") = "";
    else
        printf("ERROR: el argumento debe ser un string\n");
        print_usage ();
    endif
endfunction


--- fin maxima.m ---

martes, 6 de marzo de 2012

Acentos en Texmaker

Para poder escribir acentos en Texmaker (y posiblemente en cualquier programa para KDE) en Ubuntu, instalar:

sudo apt-get install ibus-qt4

Además, en Texmaker ir a Opciones -> Configurar Texmaker -> Editor y poner la codificación del editor en la usada para el documento (UTF-8 me funciona).

Actualización para Ubuntu 11.10:

La versión de Texmaker de los repositorios es obsoleta, y no permite escribir acentos cuando se utiliza ibus.

1) Desinstalar Texmaker.

2) Instalar la última versión, descargada desde la página oficial de Texmaker:  http://www.xm1math.net/texmaker/download.html#linux

3) Instalar ibus-qt4:

sudo apt-get install ibus-qt4

4) En Texmaker, verificar que se utilice la codificación UTF-8:
Opciones -> Configurar Texmaker -> Editor

5) A la hora de escribir, en Texmaker hacer clic con el botón derecho del ratón sobre un área de la página, y en el menú contextual elegir:
Seleccionar IM  -> ibus

viernes, 6 de mayo de 2011

Montar particiones en Ubuntu 11.04

1) Dash > Utilidad de discos

2) Seleccionar la unidad y montarla.

Para hacer que la unidad se monte automáticamente al inicio:

3) Anotar el nombre de la unidad (ej: /dev/sda4).

4) Dash > Terminal:

$ sudo gedit /etc/mtab

5)  Buscar el nombre de la unidad y copiar la línea (ej.: /dev/sda4 /media/main ext4 rw,nosuid,nodev,uhelper=udisks 0 0 ).

6) Abrir una nueva pestaña en la terminal:

$ sudo gedit /etc/fstab

7) Pegar la línea y guardar. Cerrar todas las ventanas.

8) En una terminal nueva, testear con:

$ sudo mount -a

(Si no da error, reiniciar tranquilo.)

Fuente: http://www.muktware.com/man/1075?page=0,1

viernes, 22 de abril de 2011

Cómo restaurar el panel de gnome en Ubuntu.

Para restaurar el panel de gnome a su estado original, ejecutar el comando:


gconftool --recursive-unset /apps/panel && killall gnome-panel

Probado en Ubuntu 10.10.

miércoles, 9 de marzo de 2011

Workaround para TVtime en Ubuntu 10.10

No es muy elegante, pero funciona:

1) Agregar este ppa (https://launchpad.net/~diwic/+archive/maverick) e instalar tvtime. Si pregunta, reemplazar el archivo de configuración de sonido por el nuevo.

sudo add-apt-repository ppa:diwic/maverick

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install tvtime

2) Editar el archivo de configuración de tvtime:

sudo gedit /etc/tvtime/tvtime.xml

Cambiar:

 option name="MuteOnExit" value="1"

Cambiar bind command="toggle_mute" por:

  bind command="mixer_toggle_mute"

3) Ejecutar con:

tvtime --mixer=hw:0/Line

----------------------------------------------

ACTUALIZACIÓN:


Probado en Ubuntu 11.10:


1) Instalar TVtime normalmente.


2) Editar el archivo de configuración de tvtime:

sudo gedit /etc/tvtime/tvtime.xml

Cambiar:

 option name="MuteOnExit" value="1"


Cambiar:

 option name="MixerDevice" value="hw:0/Line"



miércoles, 2 de marzo de 2011

Tasksel: Instalar LAMP en Ubuntu fácilmente.

Tasksel es una utilidad para instalar grupos de paquetes según su funcionalidad.

Para ver un listado de los grupos instalados (i) y disponibles (u), ejecutar:

tasksel --list-tasks

Para instalar un servidor LAMP (Linux - Apache - Mysql - Php), ejecutar:

sudo tasksel install lamp-server

Nota: completar la instalación del servidor LAMP con:
 sudo apt-get install phpmyadmin php-pear

miércoles, 9 de febrero de 2011

Instalar ProgramCC en Linux (con Wine)

1) Instalar wine. Debería instalarse automáticamente winetricks.

Para agregar el repositorio de wine (y obtener la última versión de wine y de winetricks):
sudo add-apt-repository ppa:ubuntu-wine/ppa

2) Ejecutar:

winetricks vcrun6sp6

Opcionalmente, para mejor compatibilidad con otras aplicaciones, ejecutar también:

winetricks vb6run

3) Descargar ProgramCC e instalarlo desde: http://programcc.com/

domingo, 16 de enero de 2011

miércoles, 12 de enero de 2011

WDT, una impresionante herramienta para desarrolladores web

"WDT (Web Developer Tools), una potente aplicación que nos permite generar de forma rápida y sencilla estilos y botones en CSS3, charts usando la API de Google, revisar el correo de Gmail, traducir texto con Google translate, realizar dibujos vectoriales, backups de bases de datos y un larguisimo (larguisimo en serio) etc."


sudo add-apt-repository ppa:petrakis/wdt-main
sudo apt-get update && sudo apt-get install -y wdt



Fuente: http://ubunlog.com/wdt-una-impresionante-herramienta-para-desarrolladores-web/

domingo, 2 de enero de 2011

Fórmulas LaTeX en Inkscape

Primero, verificar que estén instalados los paquetes pdflatex y pstoedit.


Si la opción incluída no es suficiente (Menú Extensiones -> Renderizar -> Fórmula LaTeX...), instalar la extensión textext desde:


http://pav.iki.fi/software/textext/

La extensión textext se ejecuta desde Menú Extensiones ->Tex Text.

lunes, 1 de noviembre de 2010

Sun's Java como default en Ubuntu

1) Instalar Java de Sun:
sudo apt-get install sun-java6-jre

2) Hacer Java el entorno por defecto:
sudo update-alternatives --config java

Hay 2 opciones para la alternativa java ( proporcionando /usr/bin/java).

  Selección   Ruta                                      Prioridad  Estado
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      modo automático
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      modo manual
  2            /usr/lib/jvm/java-6-sun/jre/bin/java       63        modo manual

Presione Entrar para mantener la opción actual[*], o escriba el número de la selección: 2


Fuente: https://help.ubuntu.com/community/Java

jueves, 21 de octubre de 2010

ARGUS DC-1510 como webcam en Ubuntu

¡Al fin la solución! Encontrada en: http://ubuntuforums.org/showthread.php?t=435463&highlight=argus

If your webcam reports something similar to this:

Code:
$ lsusb
Bus 001 Device 005: ID 2770:9120 NHJ, Ltd Che-ez! Snap / iClick Tiny VGA Digital Camera
Then it is now fully supported by Ubuntu (version 10.04, Lucid Lynx).

Ubuntu has, however, a bug that needs a workaround:
Code:
$ sudo modprobe -rv gspca_sq905
$ sudo modprobe -v gspca_sq905
You have to do this after every reboot or after every time you connect the camera plug.

After this you can use XawTV or VLC to see video from your webcam:
XawTV must not need any configuration. Just install and run it.
With VLC, use the "Open Capture Device" (Ctrl+C) menu and point the "Video device name" to /dev/video or /dev/video0.
aMSN must also recognise the webcam without any issues.
See the mentioned bugreport for tips on making Skype work with it (I haven't tested it).


You may also be able to download still photos or record your own movies with xawtv. Notice that these procedures were not confirmed by me on the most recent versions of Ubuntu.
Recording movies with VLC should work without any issues.

jueves, 14 de octubre de 2010

Scroll con 2 dedos en Samsung N220+

For multitouch in touchpad, I created a script and added at startup (system-->preferences-->aplication at starup or similar, I'm using spanish version). It works fine for multitouch.
You can find more info in many forums about this script.
I think that you have to enable Visual Asistance for it works


#!/bin/bash
# enable multitouch
sleep 5
synclient VertTwoFingerScroll=1
synclient HorizTwoFingerScroll=1
synclient EmulateTwoFingerMinW=5
synclient EmulateTwoFingerMinZ=48 


Fuentes:
http://seaborne.blogspot.com/2010/07/ubuntu-on-samsung-n210.html
http://josthalen.wordpress.com/2010/07/03/linux-on-samsung-n210/

viernes, 8 de octubre de 2010

Aproximación de Padé en SciLab

function P = Pade(q,n)
  // Aproximacion de Pade de orden «n» para «exp(-q.s)»
  // Calculado como:
  //      $\textrm{e}^{-\Theta\,t}\approxeq\dfrac{\sum_{k=0}^{n}\,(-1)^{k}\, c_{k}\,(\theta s)^{k}}{\sum_{k=0}^{n}\, c_{k}\,(\theta s)^{k}}$
  // donde:
  //     $c_{k}=\dfrac{(2n-k)!\, n!}{2n!\, k!\,(n-k)!}$
  // para $k=1,2,\ldots,n$
  s=poly(0,'s');
  Num = 0; // Inicializo el numerador
  Den = 0; // Inicializo el denominador
  nn = prod(1:n); // nn = n!
  n2 = prod(1:(2*n)); // n2 = 2n!
  for k=0:n
    c = (prod(1:(2*n-k))*nn)/(n2*prod(1:k)*prod(1:(n-k)));
    Num = Num + ((-1)**k)*c*(q*s)**k;
    Den = Den + c*(q*s)**k;
  end;
  P = Num/Den;
endfunction

Ahora sí, corregido.

sábado, 2 de octubre de 2010

Habilitar la interface GNOME en Ubuntu Netbook Remix 10.04

Para netbooks con soporte para aceleración 3D (Ubuntu Netbook Edition):

sudo ln -s /etc/xdg/xdg-une/autostart/maximus-autostart.desktop /etc/xdg/autostart/ #this makes Maximus run at login
sudo ln -s /etc/xdg/xdg-une/autostart/netbook-launcher.desktop /etc/xdg/autostart/ #this launches the UNE interface at login
sudo ln -s /usr/share/gconf/une/default/20_une-gconf-default /usr/share/gconf/defaults/
sudo ln -s /usr/share/gconf/une/mandatory/20_une-gconf-mandatory /usr/share/gconf/defaults/
sudo update-gconf-defaults


Para netbooks sin soporte para aceleración 3D (Ubuntu Netbook Edition 2D):

sudo ln -s /etc/xdg/xdg-une/autostart/maximus-autostart.desktop /etc/xdg/autostart/ #this makes Maximus run at login
sudo ln -s /etc/xdg/xdg-une-efl/autostart/netbook-launcher-efl.desktop /etc/xdg/autostart/ #this launches the UNE interface at login
sudo ln -s /usr/share/gconf/une/default/20_une-gconf-default /usr/share/gconf/defaults/
sudo ln -s /usr/share/gconf/une/mandatory/20_une-gconf-mandatory /usr/share/gconf/defaults/
sudo update-gconf-defaults


Para elegir una interfase, desloguearse y en la pantalla de login elegir la deseada.

Fuente: http://www.webupd8.org/2010/06/how-to-get-most-out-of-ubuntu-netbook.html