tag:blogger.com,1999:blog-341330792024-02-06T21:39:53.022-08:00Un BlogMi obligacion "Personal".Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.comBlogger62125tag:blogger.com,1999:blog-34133079.post-16873015272651007242013-04-25T20:39:00.001-07:002013-04-25T20:40:24.544-07:00Escribiendo en otros ladosSi es que alguien sigue este blog de algun modo, seria bueno fijarse en <a href="http://cardona.co">cardona.co</a> que desde hace unos meses es mi nuevo lugar.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-53531073871313943042011-04-18T08:24:00.000-07:002011-04-18T08:25:33.772-07:00La Lengua Española"Que buen idioma el mío, qué buena lengua heredamos de los conquistadores torvos..Éstos andaban a zancadas por las tremendas cordilleras, por las Américas encrespadas buscando patatas, butifarras, frijolitos, tabaco negro, oro, maíz, huevos fritos, con aquel apetito voraz que nunca más se ha visto en el mundo...Todo se lo tragaban, con religiones, pirámides, tribus, idolatrías iguales a las que ellos traían en sus grandes bolsas...Por donde pasaban quedaba arrasada la tierra...Pero a los bárbaros se les caían de las botas, de las barbas, de los yelmos, de las herraduras, como piedrecitas las palabras luminosas que se quedaron aquí resplandecientes...el idioma. Salimos perdiendo...Salimos ganando...Se llevaron el oro y nos dejaron el oro...Se lo llevaron todo y nos dejaron todo...Nos dejaron las palabras.” <br /><br />Pablo NerudaJorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-62541734375292850012010-09-27T21:59:00.000-07:002010-09-27T22:12:20.371-07:00Introducción al psicoanalisis.Ultimamente me he estado leyendo "Introducción al psicoanalisis", intentare plasmar aqui un poco lo que he aprendido y tambien las dudas que me ha traido esta lectura.<br /><br />Primero que todo el Psicoanalisis según Freud es un tratramiento para tratar neurosis, es decir enfermedades psiquicas. Se basa en el lenguaje entre el paciente y el psicoanalista. Es método cientifico, y como tal debe pararse en los pilares de este (aunque en ocasiones me parece que cojea).<br /><br />El primer tema a tratar son los actos fallidos. Los actos fallidos son una serie de equivocaciones que son normalmente pasables, como olvidar un nombre, cambiar una palabra por otra, mezclarlas, perder objetos. Son separadas ppalmente en: Equivocaciones orales, equivocaciones escritas, de aprehension, olvidos de compromisos o nombres, olvido de objetos.<br /><br />La mas tratada es la equivocacion oral. En esta el psicoanalisis propone una explicacion en la cual intervienen dos tendencias, una perturbada y otra perturbadora. La perturbada es la tendencia natural de construccion del discurso, en la cual el sujeto pone su energia, la tendencia perturbadora es aquella que modifica el discurso sin ser advertida por el sujeto. Una cita buena al filosofo Wundt es que en estas ocasiones el poder del discurso es vencido por el poder de la asociacion. Para esta explicacion Freud trae una serie de ejemplos, uno que me causo mucho interes es el de un personaje que tiene por encargo abrir una sesión, pero en el acto dice "Se levanta la sesión", cuando deberia decir: "Se abre la sesión". En el cerebro del sujeto ocurrio algo que le hace modificar el discurso, y cambiar la palabra abrir, por levantar. Inicialmente la explicacion de Freud es que "claramente" la unica interpretacion posible es que el personaje no queria abrir la sesión, y que "cualquier otra explicacion resulta ser superflua" (condenar al fracaso un argumento en contra no parece ser muy acorde al metodo cientifico). Otro caso, es el de un amigo de Freud que tenia un perro enfermo, en este caso el amigo le comenta que "drurara asi un mes mas", a lo cual Freud lo corrige y el amigo responde diciendo que pensaba decir "tristemente durara así un mes", pero combino las palabras.<br /><br />En esencia todas estas equivocaciones tienen una tendencia original y otra que tiende a perturbarla, la cual suele ser una tendencia escondida y toca analisar al sujeto para encontrar y explicar el porque de la equivocacion.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-82208806114968625682010-09-27T21:30:00.000-07:002010-09-27T21:55:17.089-07:00Django nonrel + MongoDB.I want to setup a basic virtualenv environment with a working version of django-nonrel with MongoDB.<br /><br />From http://www.allbuttonspressed.com/projects/django-nonrel we can read a blog entry that explains everything about the integration: http://www.allbuttonspressed.com/blog/django/2010/05/MongoDB-backend-for-Django-nonrel-released<br /><br />With requirements.txt:<br /><pre class="brush:bash"><br />pymongo<br />-e git+http://github.com/aparo/django-mongodb-engine.git#egg=django_mongodb_engine<br />-e hg+http://bitbucket.org/wkornewald/django-nonrel#egg=Django<br />-e hg+http://bitbucket.org/wkornewald/djangotoolbox#egg=djangotoolbox<br /></pre><br /><br />Type:<br /><br /><pre class="brush:bash"><br />aptitude install python-pip<br />pip install virtualenv<br />virtualenv --no-site-packages --distribute nonrel<br />cd norel<br />. bin/activate<br />pip -r ../requirements.txt<br />bin/django-admin.py startproject myproject<br /></pre><br /><br />Define your database as:<br /><br /><pre class="brush:bash"><br />DATABASES = {<br /> 'default': {<br /> 'ENGINE': 'django_mongodb_engine.mongodb',<br /> 'NAME': 'test',<br /> 'USER': 'test',<br /> 'PASSWORD': 'test',<br /> 'HOST': 'flame.mongohq.com',<br /> 'PORT': 99999,<br /> 'SUPPORTS_TRANSACTIONS': False,<br /> }<br />}<br /></pre><br /><br />Pretty easy.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-11458844600071440162010-07-02T13:17:00.000-07:002010-07-02T13:39:29.794-07:00Identity, Authentication, Authorization and MultitenancyThere it should somewhere in the web an application to correctly build a Django site with those concepts.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-18774095680405021572010-06-05T21:30:00.000-07:002010-06-05T22:00:01.322-07:00Un poco de genealogia.Ayer en un bar un personaje dijo, hablando de Juan Manuel Santos: "No solo nos roban la plata sino tambien la opinion", me surgio la duda de conocer bien las relaciones familiares de los Santos.<br /><br />Eduardo Santos Montejo (Presidente de Colombia 1938-1942) hermano de Enrique Santos Montejo, este ultimo padre de Enrique Santos Castillo y Hernando Santos Castillos. Tambien es hijo Enrique Santos Molano, con una tal Blanca Molano, de la cual poco encuentro.<br /><br />Ahora, Enrique Santos Castillo y Hernando Santos Castillo se casaron con dos hermanas de apellido Calderon, y fueron traidas al mundo cuatro criaturas: Juan Manuel Santos Calderon(ex-ministro de Defensa) y Enrique Santos Calderon (director de El Tiempo hasta el 2009) son hijos de Enrique Santos Calderon. Francisco Santos Calderon (Vicepresidente) y Rafael Santos Castillo (director de El Tiempo hasta el 2009) hijos de Hernando Santos Castillo.<br /><br />Encontre un documento en: http://www.interconexioncolombia.com/documentos/genealogia/que%20esta%20pasando%20en%20colombia/Los%20Santos%20y%20los%20Lopez%20nos%20gobiernan%20desde%201930.pdf<br />En donde se pueden ver diagramas de Genealogias, es interesante ver en un solo diagrama nombres como: Alvaro Uribe Velez, Jose Obdulio Gaviria, Pablo Escobar Gaviria, Fabio Ochoa, Noemi Sanin.<br /><br />Basicamente el documento relaciona a todos los actores de este gran teatro llamado Colombia.<br /><br />Como dicen por ahi: Todo queda en Familia.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com1tag:blogger.com,1999:blog-34133079.post-85169818987996408752010-04-11T23:06:00.000-07:002010-04-11T23:07:02.527-07:00Mockus!!!<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/jr74PjfEryk&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/jr74PjfEryk&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-10280640734499619012010-03-25T20:57:00.000-07:002010-03-25T21:18:13.690-07:00Antanas Mockus Presidente de Colombia 2010 - 2014En este pequeño espacio posiblemente con pocas visitas intentare ayudar a una justa causa por mi país.<br /><br />Partido Verde.<br /><br /><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/STIEHh6PsUc&color1=0xb1b1b1&color2=0xcfcfcf&hl=es_ES&feature=player_embedded&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/STIEHh6PsUc&color1=0xb1b1b1&color2=0xcfcfcf&hl=es_ES&feature=player_embedded&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="385"></embed></object><br /><br /><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/TYl5si4iE6g&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/TYl5si4iE6g&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-5579673242906557152010-01-31T11:40:00.000-08:002010-01-31T13:15:42.784-08:00Latex + Inline spell checkWell, after 3 days of trying to activate a good inline spell check on Kile, which is impossible right now, and after trying to compile the hello world plugin for Kate to create a plugin that highlight that misspelled words, which is almost impossible too because of some mistakes on the example, and trying to use emacs for latex + flyspell (it works, but is not very nice), I found that Gedit with its plugin for latex is now really great and has inline spell check!!!, also it list all the structure of the document in a side panel, and has more features, and the best is that is a Gnome app.<br /><br />http://projects.gnome.org/gedit/<br />http://live.gnome.org/Gedit/LaTeXPluginJorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-42500933587759396082010-01-04T20:42:00.000-08:002010-01-04T22:23:50.558-08:00I love my Linux Kernel.Well, I just love it. <br /><br />Right now I'm working in a driver for a couple of circuits with a DAC, ADC and a encoder to connect my old Gumstix Connex to a PLC Unitronics, and two Variable speed driver Altivar ATV31.<br /><br />The driver basically read through SPI the data that the ADC get from a current loop. And through SPI the resulting data is send to the drivers. The encoder work with three GPIO interrupt.<br /><br />I'll try to write later on this. For now, a couple of pages that are really helpful:<br /><br />http://www.linuxjournal.com/article/5833<br />http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/<br />http://www.linuxgrill.com/anonymous/fire/netfilter/kernel-hacking-HOWTO-5.html<br />http://people.nl.linux.org/ftp/pub/anoncvs/kernelnewbies/documents/kdoc/kernel-api/adt.html#AEN475<br />http://docs.huihoo.com/linux/kernel/2.6.26/kernel-api/ch25.html<br />http://docwiki.gumstix.org/index.php/Robostix_spi.c<br />http://www.makelinux.net/ldd3/ (The chapters with locking techniques, procfs, and deferred work are great!!!)<br />http://tldp.org/LDP/lkmpg/2.6/html/x1256.htmlJorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-86571499015308162722009-12-28T15:07:00.001-08:002009-12-28T18:56:54.320-08:00Corrupted GitWell, I have a directory with all my undergraduate project and I use git to ease my work, but recently I was not able to create a backup in a external disk because a error:<br /><br /><pre class="brush:bash"><br />remote: Counting objects: 313, done.<br />remote: Compressing objects: 100% (116/116), done.<br />fatal: pack has bad object at offset 11893474: inflate returned 1<br />fatal: index-pack failed<br /></pre><br /><br />I have files of almost 500MB on this repo, I suppose that the problem. I try to repack but it was useless, I also can check the hash of the object (with fsck), but I can't find where is that file, or what commit it belongs to. <br /><br />This code will help in this case:<br /><br /><pre class="brush:bash"><br />git checkout master<br />git branch new_master<br />git checkout new_master<br />for i in $!$(seq 1 100); do git checkout new_master~$!$i || break; done<br />for j in $!$(seq $!$i 100); do git checkout new_master~$!$j && break; done<br /># The error is between new_master~$!$j and new_master~($!$i-2)<br />git checkout master<br />git branch -D new_master<br />git branch new_master<br />git checkout new_master<br />git rebase --onto new_master~$!$j new_master~$!$((i-2)) new_master<br /></pre><br /><br />It works (al least for my problem!!!), and now i want to rebase master:<br /><pre class="brush:bash"><br />git checkout master<br />git rebase new_master<br />git branch -d new_master<br /></pre><br /><br />That's all.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-60505059554539821362009-12-03T21:19:00.001-08:002010-03-22T11:07:55.102-07:00Compute the normal vector of a hyperplane in $R^n$Well, basically any vector $N$ that holds $N \dot (p_i - p_j) = 0$ for for any vector $p_i, p_j \in H$ $H$ is the hyperplane.<br /><br />Only $n$ different points are needed, call $P$ the set of $n$ points in $H$, and define $P^* = \{ p^*_i = p_i - p_{i+1} : p_i,p_{i+1} \in H , i \in [1,n-1]\}$.<br /><br />$P^*$ is the set of vectors on $H$.<br /><br />Any normal vector $N$ that holds that $N \dot p^*_i , i \in [1,n-1]$ is a normal vector.<br /><br />$N$ has $n$ components, so we got here $n$ unknowns. And with the $n_1$ $p^*_i$ vectors we got $n-1$ equations.<br /><br />An extra equation could be defined if we want a normalized vector, but this add a quadratic term in the systems, as the vector with all zero components can't be a normal vector of any hyperplane at least one of its components has a non-zero value, suppose that the $j$ component of $N$ has value $1$. and we have then a Ax = B, with n-1 equations and unknowns. we just have to try which j makes the systm non singular and solve it.<br /><br /><br />The system of equations:<br />$\begin{pmatrix}<br />p^*_{1,1} & p^*_{1,2} & \cdots & p^*_{1,j-1} & p^*_{1,j+1} & \cdots & p^*_{1,n} \\ p^*_{2,1} & p^*_{2,2} & \cdots & p^*_{2,j-1} & p^*_{2,j+1} & \cdots & p^*_{2,n} \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\<br />p^*_{n,1} & p^*_{n,2} & \cdots & p^*_{n,j-1} & p^*_{n,j+1} & \cdots & p^*_{n,n} \\ <br />\end{pmatrix} \begin{pmatrix} N_1 \\ N_2 \\ \vdots \\ N_{j-1} \\ N_{j+1} \\ \vdots \\ N_n \end{pmatrix} = - \begin{pmatrix} p^*_{1,j} \\ p^*_{2,j} \\ \vdots \\ p^*_{(j-1),j} \\ p^*_{(j-1),j} \\ \vdots \\ p^*_{n,j} \end{pmatrix}<br />$<br /><br />Start checking for $j \in [1,n]$ and you will get at much $n$ and at least 1 normal vector.<br /><br />Python:<br /><br /><pre class="brush: python" ><br />from numpy import array, dot<br />from numpy.linalg import solve, norm<br /><br /><br />def normal(P):<br /> n = len(P)<br /><br /> if n < 1:<br /> raise Exception, "O-size list."<br /><br /> m = len(P[0])<br /><br /> if array([len(p) != m for p in P]).any():<br /> raise Exception, "Inconsistent set of points."<br /><br /> if n != m:<br /> raise Exception<br /><br /> P_ = [p-q for p,q in zip(P[:-1],P[1:])]<br /><br /> N = []<br /><br /> for i in range(n):<br /> try:<br /> x = solve(<br /> array([list(p)[:i] + list(p)[i+1:] for p in P_]),<br /> array([-p[i] for p in P_])<br /> )<br /><br /> x = array(list(x)[:i] + [1] + list(x)[i:])<br /> N.append(x)<br /><br /> except:<br /> pass<br /><br /> n = N[array([(dot(n,n)-1)**2 for n in N]).argmin()]<br /><br /> return n / norm(n)<br /><br /><br /><br />if __name__ == '__main__':<br /> print normal([array([1,0,0]), array([0,1,0]), array([1,1,0])])<br /> print normal([array([1,123,0123]), array([0345,1,034]), array([132,134,034])])<br /> print normal([array([1,0,0]), array([0,1,0]), array([1,123,1123])])<br /></pre>Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-65912549468001505072009-12-03T05:51:00.000-08:002009-12-03T13:32:32.141-08:00I'm gonna create a image with Debian and Django to upload it to AWS.<br /><br /><br /><pre class="brush: bash"><br />dd if=/dev/zero of=debian-ami count=1000 bs=1m<br />sudo mkfs.ext3 -F debian-ami<br />mkdir /tmp/chroot<br />sudo mount -o loop debian-ami /tmp/chroot<br />sudo debootstrap --arch i386 lenny /tmp/chroot/ http://ftp.debian.org<br />sudo chroot /tmp/chroot/<br /># Inside the chroot<br />mount -t proc none /proc<br />cd /dev<br />MAKEDEV console<br />MAKEDEV std<br />echo -e 'auto lo\niface lo inet loopback\nauto eth0\niface eth0 inet dhcp' >> /etc/network/interfaces<br />echo -e 'proc /proc proc defaults 0 0\n/dev/sda1 / reiserfs defaults 0 1\n/dev/sda2 swap swap defaults 0 0' > /etc/fstab<br />aptitude update<br />aptitude install locales-all<br />aptitude install ssh<br />exit<br /><br /># In your machine<br />sudo umount -l /tmp/chroot <br />export EC2_PRIVATE_KEY=xxxxxxx.pem<br />export EC2_CERT=xxxxxxxxxxxxxxxxxx.pem<br />export EC2_ACCNO=xxxxxxxxxx<br />export ACCESS_KEY=xxxxxxxxxxxxxxxx<br />export SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<br />ec2-bundle-image -i debian-ami --cert EC2_CERT --privatekey EC2_PRIVATE_KEY -u EC2_ACCNO<br />ec2-upload-bundle -b 20091203-linux-debian-lenny -m /tmp/debian-ami.manifest.xml -a ACCESS_KEY -s SECRET_KEY<br />ec2-register -n 20091203-linux-debian-lenny 20091203-linux-debian-lenny/debian-ami.manifest.xml<br /></pre>Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-48210892339255057262009-08-23T13:20:00.000-07:002009-08-24T00:31:56.470-07:00AlgebraI'm studying algebra with some friends, and i will try to write here what subjects are we studying right now.<br /><br />We start with Abstract Algebra using Hungerford book, but i want to follow the MITOpenCourseWare about Algebra I (http://ocw.mit.edu/OcwWeb/Mathematics/18-701Fall-2007/Readings/index.htm).<br /><br /><span style="font-weight:bold;">Composition Law:</span><br />A composition law $f$ select a pair of elements on a set $S$ and return an element of $S$, ie:<br />$f : S \times S \rightarrow S$, I will write $f(a,b)$ as $a*b$ for seek of simplicity.<br /><br />If $*$ holds that $(a*b)*c = a*(b*c) \quad \forall a,b,c \in S$ then we say that is an associative law.<br /><br />If $*$ holds that $a*b=b*a \quad \forall a,b \in S$ we say that is a commutative law.<br /><br /><span style="font-weight:bold;">Semigroups</span><br /><br />Let $S$ be a set and $*$ be a composition law on $S$, if $*$ is associative then $(S,*)$ is a semigroup.<br /><br /><span style="font-weight:bold;">Monoids</span><br /><br />Let $(S,*)$ be a semigroup if $S$ has an identity element $e$ such that:<br /><br />$\forall x \in S$ $x*e = x = e*x$,<br /><br />then $(S,*)$ is a Monoid.<br /><br /><span style="font-weight:bold;">Groups</span><br /><br />Let $(S,*)$ be a Monoid if:<br /><br />$\forall x \in S$ $\exists x^{-1} \in S$ s.t. $x*x^{-1} = e = x^{-1}*x$,<br /><br />then $(S,*)$ is a Group.<br /><br />if $*$ is commutative then $(S,*)$ is a commutative or Abelian group.<br /><br /><strong>Subgroups</strong><br /><br />Let $(G,*)$ be a group, if a proper subset $H$ of $G$ is also a group with $*$ then $H$ is a subgroup of $G$<br /><br /><em>Theorem</em><br /><br />If $(G,*)$ is a group and $H$ is a nonempty subset of $G$:<br /><br />$(H,*)$ is a subgroup of $(G,*)$ if and only if $a*b^{-1} \in H \quad \forall a,b \in H$<br /><br /><span style="font-weight:bold;">Relation</span><br /><br />Let $A$ and $B$ be sets and $R$ a map from $A$ to $B$ s.t.:<br /><br />$R : A \rightarrow B$<br />with $a\in A$ and $b=R(a) \in B$ and<br />$(a,b) = (a,R(a)) \in A \times B$<br />for seek of simplicity we write $(a,R(a)) \in A \times B$ as $aRb$.<br /><br /><span style="font-weight:bold;">Equivalence Relations</span><br /><br />Let $S$ be a set and $R$ a relation in $S \times S$, if:<br /><br />i) $aRa \quad \forall a \in S$ (Reflexive)<br /><br />ii) $aRb \implies bRa$ (Symmetric)<br /><br />iii) $aRb \wedge bRc \implies aRc$ (Transitive)<br /><br />then $R$ is an Equivalence Relation on $S$. (When we speak of an equivalence relation we'll use the symbol $=$)<br /><br /><span style="font-weight:bold;">Partial Order Relations</span><br /><br />A partial order relation is a relation $R$ in a set $S$ with a equivalence relation $=$ if $R$ is reflexive and transitive and:<br /><br />$aRb \wedge bRa \implies a=b$ (antisymmetric)<br /><br />We write a partial order relation as $\leq$. The above oreder is a non-strict relation.<br /><br />A strict partial relation order $R$ in $S$ is:<br /><br />i) $a\not R a \quad \forall a \in S$ (irreflexive)<br /><br />ii) $aRb \wedge bRa \implies a=b$ (antisymmetric)<br /><br />iii) $aRb \wedge bRc \implies aRc$ (Transitive)<br /><br />We write a strict partial order relation as $<$.<br /><br /><span style="font-weight:bold;">Complete Order Relations</span><br /><br />The above partial relations don't hold $\forall a,b \in S$, if they do then the order is a complete order.<br /><br /><span style="font-weight:bold;">Congruence Relation</span><br /><br />Let $(G,*)$ be a Monoid, if a equivalence relation $=$ on $G$ also holds that:<br /><br />$a_1=a_2 \wedge b_1 = b_2 \implies a_1*b_1 = a_2*b_2$,<br /><br />then $=$ is also congruence relation.<br /><br /><span style="font-weight:bold;">Equivalence Classes</span><br /><br />Let $S$ be a set with an equivalence relations $=$, the equivalence class $\bar{a}$ (or $[a]$) of an element $a \in S$ is:<br /><br />$\bar{a} = \{ x \in S | x = a \}$<br /><br />The class of all the equivalence classes on $S$ is denoted as $(S/=)$, and is called the quotient class of $S$ by $=$.<br /><br />The union of all the equivalence classes is $S$, i.e. <br /><br />$\bigcup_{a \in S} \bar{a} = A = \bigcup_{\bar{a} \in (S/=)} \bar{a}$ or $\bar{a} = \bar{b}$<br /><br />If $a,b \in S$ either $\bar{a} \cap \bar{b} = \emptyset$<br /><br /><span style="font-style:italic;">Theorem:</span><br />Let $(G,*)$ be a Monoid and $=$ a congruence relation on $G$, then:<br /><br />$((G/=), *)$ is a Monoid with<br /><br />$* : (G/=) \times (G/=) \rightarrow (G/=)$ and $[a]*[b] = [a*b] \quad [a],[b] \in G/=$ (sorry for the change on notation but the bar don't expand enough in the a*b)<br /><br />If $(G,*)$ is Abelian then $(G/=,*)$ is Abelian too.<br /><br /><span style="font-weight:bold;">Group Homomorphism</span><br /><br />Let $(G,\circ)$ and $(H,\diamond)$ be two groups and a function $f : G \rightarrow H$ such that:<br /><br />$f(x \circ y ) = f(x) \diamond f(y) \quad \forall x,y \in G$,<br /><br />then $f$ is a Group homomorphism.<br /><br />If $f$ is injective then $f$ is a Group Monomorphism.<br /><br />If $f$ is surjective then $f$ is a Group Epimorphism.<br /><br />If $f$ is bijective then $f$ is a Group Isomorphism.<br /><br />If a Group Homomorphism is $f: G \rightarrow G$ then $f$ is a Group Endomorphism of $G$.<br /><br />If a Group Isomorphism is $f: G \rightarrow G$ then $f$ is a Group Automorphism of $G$.<br /><br /><span style="font-weight:bold;">Kernel</span><br /><br />Let $(G,\circ)$ and $(H,\diamond)$ be two groups and a homomorphism $f : G \rightarrow H$. $e_G$ and $e_H$ are the ideintity element of each group, then, the kernel of $f$ is:<br /><br />$Ker f = \{a \in G | f(a) = e_H\}$,<br /><br />The kernel is a subset of $G$ that maps to the identity element on $H$ with the homomorphism $f$.<br /><br /><span style="font-style:italic;">Theorem:</span><br />If $f : G \rightarrow H$ is a monomorphism $\Longleftrightarrow$ $Ker f = \{e_G\}$<br /><br /><span style="font-style:italic;">Theorem:</span><br />If $f : G \rightarrow H$ is a isomorphism $\Longleftrightarrow$ $f^{-1} : H \rightarrow G$ is a homomorphism and $f(f^{-1}(a)) = a \quad \forall a \in H$ and $f^{-1}(f(a)) = a \quad \forall a \in G$<br /><br /><span style="font-weight:bold;">Cyclic groups</span><br /><br />Let $(G,*)$ be a group and $X$ a subset of $G$.<br /><br />Let $\{ H_i | i \in I \}$ be the family of all the subgroups ($H_i$) of $G$ that contains $X$ i.e. $X \subset H_i \forall i \in I$<br /><br />$\bigcap_{i \in I} H_i$ is a subgroup of $G$ generated by $X$ and denoted $\langle X\rangle$<br /><br />The elements of $X$ are the generators of $\langle X\rangle$.<br /><br />Several different subsets on $G$ can generate the same $\langle X\rangle$, so, in general $\langle X\rangle = \langle Y \rangle$ with $X \neq Y$.<br /><br />If $X$ is a finite set such that $X = \{a_1, a_2, \cdots , a_n \}$, we write $\langle a_1, a_2, \cdots, a_n \rangle$ instead of $\langle X\rangle$.<br /><br />If $G = \langle a_1,a_2, \cdots, a_n \rangle$ with $a_i \in G$, then $G$ is said to be finitely generated.<br /><br />If $a \in G$, then the subgroup $\langle a\rangle$ is the Cyclic Group or Cyclic Subgroup generaterd by a.<br /><br /><span style="font-style:italic;">Theorem</span><br /><br />Let $(G,*)$ be a group and $X$ a nonempty subset of $G$, then the subgroup $\langle X \rangle$ generated by $X$ consists of all finite products $a_1^{n_1}a_2^{n_2}\cdots a_1t^{n_t} \quad a_i \in X; \quad n_i \in \mathbb{Z}$.<br /><br />And $\forall a \in G, \langle a \rangle = \{ a^n | n \in \mathbb{Z}\}$<br /><br /><span style="font-style:italic;">Theorem</span><br /><br />Let $H$ be a cycli subgroup of $(\mathbb{Z},+)$, either $H=\langle 0 \rangle$ or $H=\langle m \rangle$, with $m$ the least positive integer in $H$, then if $H \neq \langle 0 \rangle$, then $H$ is infinite.<br /><br /><span style="font-style:italic;">Theorem</span><br /><br />Every infinite cyclic group is isomorphic to $(\mathbb{Z},+)$ and every finite cyclic group of order $m$ is isomorphic to $(\mathbb{Z}_m,+)$ (¿¿¿$\langle m \rangle$???).<br /><br /><span style="font-weight:bold;">Cosets</span><br /><br />First we define that $a \equiv b (mod m) \Longleftrightarrow m | a - b \Longleftrightarrow a-b \in \langle m \rangle$.<br /><br />Let $(G,*)$ be a group, and $(H,*)$ a subgroup of $(G,*)$ and $a,b \in G$.<br /><br />a is <i>right congruent</i> to $b$ modulo $H$, denoted as $a \equiv_r b (mod H)$ if $a*b^{-1} \in H$.<br /><br />a is <i>left congruent</i> to $b$ modulo $H$, denoted as $a \equiv_l b (mod H)$ if $a^{-1}*b \in H$.<br /><br />If $G$ is abelian then if one of the congruencies hold then the other does:<br /><br />$a*b^{-1} \in H \Longleftrightarrow (a*b^{-1})^{-1} \in H$<br /><br />$(a*b^{-1})^{-1} = b*a^{-1} = a^{-1}*b$<br /><br /> and<br /><br />$a^{-1}*b \in H \Longleftrightarrow (a^{-1}*b)^{-1} \in H$<br /><br />$(a^{-1}*b)^{-1} = b^{-1}*a = a*b^{-1}$<br /><br /><span style="font-style:italic;">Theorem</span><br /><br />Let $(H,*)$ be a subgroup of $(G,*)$, then<br /><br />i) Right(Left) congruence modulo $H$ is an equivalence relation on $G$.<br /><br />ii) The equivalence class of $a \in G$ with the right (left) congruence is the set $Ha = \{h*a | h \in H\} ($aH = \{a*h | h \in H\})<br /><br />iii) $|Ha| = |H| = |aH| \quad \forall a \in G$<br /><br />$Ha$ is called a right coset of $H$ in $G$.<br />$aH$ is called a left coset of $H$ in $G$.<br /><br /><br /><span style="font-style:italic;">Corollary</span><br /><br />i) $G$ is the union of the right(left) cosets of $H$ on $G$.<br /><br />ii) Two right(left) cosets of $H$ on $G$ are either disjoint or equal.<br /><br />iii) $\forall a,b \in G, \quad Ha = Hb \Longleftrightarrow a*b^{-1} \in H$ and $aH = bH \Longleftrightarrow a^{-1}*b \in H$<br /><br />iv) If $R$ is the set of distinct right(left) cosets of $H$ in $G$, and $L$ is the set of distinct left cosets of $H$ in $G$, then <br /><br /><span style="font-style:italic;">Definition</span><br /><br />Let $(G,*)$ be a group, and $(H,*)$ a subgroup of $(G,*)$ the index of $H$ in $G$, denoted as $[G : H]$ is the cardinal number of the set of distinct right(left) cosets. of $H$ in $G$.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-40092646038398726452009-08-22T18:56:00.001-07:002009-08-22T19:02:34.994-07:00Runge Kutta in HaskellWell, Runge-Kutta is a better solver that Euler so:<br /><br /><pre class="hl"><br /><span class="hl slc">-- Runge-Kutta method (t_o, t_f,h, x_o, function(t,x))</span><br />runge t_o t_f h x_o f <span class="hl sym">=</span> <span class="hl kwd">case</span> t_o <span class="hl sym"><</span> t_f <span class="hl kwd">of</span><br /> <span class="hl kwa">True</span> <span class="hl sym">-></span><br /> <span class="hl kwd">do</span><br /> <span class="hl kwd">let</span> k_1 <span class="hl sym">=</span> f t_o x_o<br /> <span class="hl kwd">let</span> k_2 <span class="hl sym">=</span> f <span class="hl sym">(</span>t_o <span class="hl sym">+</span> h<span class="hl sym">/</span><span class="hl num">2</span><span class="hl sym">) (</span>x_o <span class="hl sym">+</span> h <span class="hl sym">*</span> k_1 <span class="hl sym">/</span> <span class="hl num">2</span><span class="hl sym">)</span><br /> <span class="hl kwd">let</span> k_3 <span class="hl sym">=</span> f <span class="hl sym">(</span>t_o <span class="hl sym">+</span> h<span class="hl sym">/</span><span class="hl num">2</span><span class="hl sym">) (</span>x_o <span class="hl sym">+</span> h <span class="hl sym">*</span> k_2 <span class="hl sym">/</span> <span class="hl num">2</span><span class="hl sym">)</span><br /> <span class="hl kwd">let</span> k_4 <span class="hl sym">=</span> f <span class="hl sym">(</span>t_o <span class="hl sym">+</span> h<span class="hl sym">) (</span>x_o <span class="hl sym">+</span> h <span class="hl sym">*</span> k_3<span class="hl sym">)</span><br /> <span class="hl sym">[(</span>t_o<span class="hl sym">,</span>x_o<span class="hl sym">)] ++ (</span> runge <span class="hl sym">(</span>t_o <span class="hl sym">+</span> h<span class="hl sym">)</span> t_f h <span class="hl sym">(</span>x_o <span class="hl sym">+</span> h <span class="hl sym">* (</span>k_1 <span class="hl sym">+</span> <span class="hl num">2</span><span class="hl sym">*</span>k_2 <span class="hl sym">+</span> <span class="hl num">2</span><span class="hl sym">*</span>k_3 <span class="hl sym">+</span> k_4<span class="hl sym">) /</span> <span class="hl num">6</span><span class="hl sym">)</span> f<span class="hl sym">)</span><br /> <span class="hl kwa">False</span> <span class="hl sym">-></span><br /> <span class="hl sym">[]</span><br /><br /><br /><span class="hl slc">-- Function</span><br />f <span class="hl sym">::</span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span><br />f t x <span class="hl sym">= -</span> x<br /><br /><span class="hl slc">-- Print in column</span><br />show_col <span class="hl sym">:: [(</span><span class="hl kwb">Double</span><span class="hl sym">,</span> <span class="hl kwb">Double</span><span class="hl sym">)] -></span> <span class="hl kwb">String</span><br />show_col x <span class="hl sym">=</span> <span class="hl kwd">case</span> x <span class="hl kwd">of</span><br /> <span class="hl sym">(</span>a<span class="hl sym">:</span>b<span class="hl sym">) -></span><br /> <span class="hl kwd">do</span><br /> <span class="hl kwd">let</span> <span class="hl sym">(</span>t<span class="hl sym">,</span> v<span class="hl sym">) =</span> a<br /> <span class="hl sym">(</span><span class="hl kwc">show</span> t<span class="hl sym">) ++</span> <span class="hl str">" , "</span> <span class="hl sym">++ (</span><span class="hl kwc">show</span> v<span class="hl sym">) ++</span> <span class="hl str">"\n"</span> <span class="hl sym">++ (</span>show_col b<span class="hl sym">)</span><br /> <span class="hl sym">[] -></span><br /> <span class="hl str">""</span><br /><br />main <span class="hl sym">=</span> <span class="hl kwc">putStrLn</span><span class="hl sym">(</span>show_col<span class="hl sym">(</span>runge <span class="hl num">0 5 0.01 10</span> f<span class="hl sym">))</span><br /></pre>Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-28730944295973581692009-08-21T16:02:00.001-07:002009-08-22T17:54:36.511-07:00Euler Method in HaskellI decide today to learn haskell, but i can't get out of my head how could it be used in simulation, so, i will try with several basic solvers, starting with Euler Method to solve: y'(t) = f(t, y(t))<br /><br /><pre class="hl"><br /><span class="hl slc">--Euler method (t_o, t_f,h, x_o, function(t,x))</span><br />euler1 <span class="hl sym">::</span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span> <span class="hl sym">-> (</span><span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span><span class="hl sym">) -> [(</span><span class="hl kwb">Double</span><span class="hl sym">,</span> <span class="hl kwb">Double</span><span class="hl sym">)]</span><br />euler1 t_o t_f h x_o f <span class="hl sym">=</span> <span class="hl kwd">case</span> t_o <span class="hl sym"><</span> t_f <span class="hl kwd">of</span><br /> <span class="hl kwa">True</span> <span class="hl sym">-></span><br /> <span class="hl sym">[(</span>t_o<span class="hl sym">,</span>x_o<span class="hl sym">)] ++ (</span>euler1 <span class="hl sym">(</span>t_o<span class="hl sym">+</span>h<span class="hl sym">)</span> t_f h <span class="hl sym">(</span>x_o<span class="hl sym">+(</span>h <span class="hl sym">*</span> f t_o x_o<span class="hl sym">))</span> f<span class="hl sym">)</span><br /> <span class="hl kwa">False</span> <span class="hl sym">-></span><br /> <span class="hl sym">[]</span><br /><br /><br /><br /><span class="hl slc">--Euler method (t_o, t_f,steps, x_o, function(t,x))</span><br />euler2 <span class="hl sym">::</span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Integer</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span> <span class="hl sym">-> (</span><span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span><span class="hl sym">) -> [(</span><span class="hl kwb">Double</span><span class="hl sym">,</span> <span class="hl kwb">Double</span><span class="hl sym">)]</span><br />euler2 t_o t_f steps x_o f <span class="hl sym">=</span> <span class="hl kwd">case</span> steps <span class="hl sym">></span> <span class="hl num">0</span> <span class="hl kwd">of</span><br /> <span class="hl kwa">True</span> <span class="hl sym">-></span><br /> <span class="hl kwd">do</span><br /> <span class="hl kwd">let</span> h <span class="hl sym">= (</span>t_f <span class="hl sym">-</span> t_o<span class="hl sym">) / (</span><span class="hl kwc">fromIntegral</span> steps<span class="hl sym">)</span><br /> <span class="hl sym">[(</span>t_o<span class="hl sym">,</span> x_o<span class="hl sym">)] ++</span> euler2 <span class="hl sym">(</span>t_o <span class="hl sym">+</span> h<span class="hl sym">)</span> t_f <span class="hl sym">(</span>steps <span class="hl sym">-</span> <span class="hl num">1</span><span class="hl sym">) (</span>x_o <span class="hl sym">+ (</span>h <span class="hl sym">*</span> f t_o x_o<span class="hl sym">))</span> f<br /> <span class="hl kwa">False</span> <span class="hl sym">-></span><br /> <span class="hl sym">[]</span><br /><br /><br /><br /><span class="hl slc">-- Function</span><br />f <span class="hl sym">::</span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span> <span class="hl sym">-></span> <span class="hl kwb">Double</span><br />f t x <span class="hl sym">= -</span> x<br /><br /><span class="hl slc">-- Print in column</span><br />show_col <span class="hl sym">:: [(</span><span class="hl kwb">Double</span><span class="hl sym">,</span> <span class="hl kwb">Double</span><span class="hl sym">)] -></span> <span class="hl kwb">String</span><br />show_col x <span class="hl sym">=</span> <span class="hl kwd">case</span> x <span class="hl kwd">of</span><br /> <span class="hl sym">(</span>a<span class="hl sym">:</span>b<span class="hl sym">) -></span><br /> <span class="hl kwd">do</span><br /> <span class="hl kwd">let</span> <span class="hl sym">(</span>t<span class="hl sym">,</span> v<span class="hl sym">) =</span> a<br /> <span class="hl sym">(</span><span class="hl kwc">show</span> t<span class="hl sym">) ++</span> <span class="hl str">" , "</span> <span class="hl sym">++ (</span><span class="hl kwc">show</span> v<span class="hl sym">) ++</span> <span class="hl str">"\n"</span> <span class="hl sym">++ (</span>show_col b<span class="hl sym">)</span><br /> <span class="hl sym">[] -></span><br /> <span class="hl str">""</span><br /><br /><span class="hl slc">--main = putStrLn(show_col(euler1 0 1 0.00001 10 f))</span><br />main <span class="hl sym">=</span> <span class="hl kwc">putStrLn</span><span class="hl sym">(</span>show_col<span class="hl sym">(</span>euler2 <span class="hl num">0 1 100000 10</span> f<span class="hl sym">))</span><br /></pre>Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-82598251470237518462009-08-13T16:16:00.000-07:002009-08-13T17:10:13.882-07:00QucsMmmm, Creo que por fin encontre un buen programa para simular circuitos, trabaja con SPICE y ademas es libre.<br /><br />http://qucs.sourceforge.net/<br />http://qucs.sourceforge.net/docs.html<br />http://qucs.sourceforge.net/download.htmlJorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-23611086271161340222009-08-12T21:57:00.001-07:002009-08-12T23:32:19.917-07:00Symbolic Integration (Manuel Bronstein)Well, now that i have a new book, Symbolic Integration I of Manuel Bronstein, i will implement some of the code examples on the initial chapter: polydivide, euclidean algorithm, square free factorization, all of them using GiNaC library.<br /><br /><span style="font-weight:bold;">PolyDivide </span><br /><br />This one find the unique q and r in a field K[z] that holds a = b*q + r<br /><br /><pre name="code" class="cpp"><br />lst PolyDivide(ex A, ex B, symbol x)<br />{<br /> ex Q = 0;<br /> ex R = A;<br /><br /> int d = R.degree(x) - B.degree(x);<br /><br /> while ((not R.is_zero()) and (d >=0))<br /> {<br /> ex T = R.lcoeff(x) / B.lcoeff(x) * pow(x,d);<br /> Q = expand(Q + T);<br /> R = expand(R - B*T);<br /> d = R.degree(x) - B.degree(x);<br /> }<br /> return lst(Q,R);<br />}<br /></pre><br /><br /><span style="font-weight:bold;">PolyPseudoDivide</span><br />Same that last, but in a integral domain, like Z.<br /><br /><pre name="code" class="cpp"><br />lst PolyPseudoDivide(ex A, ex B, symbol x)<br />{<br /> ex b = B.lcoeff(x);<br /> int N = A.degree(x) - B.degree(x) + 1;<br /> ex Q = 0;<br /> ex R = A;<br /><br /> int d = R.degree(x) - B.degree(x);<br /><br /> while ((not R.is_zero()) and (d >=0))<br /> {<br /> ex T = R.lcoeff(x) * pow(x,d);<br /> N -= 1;<br /> Q = expand(b * Q + T);<br /> R = expand(b * R - T * B);<br /> d = R.degree(x) - B.degree(x);<br /> }<br /><br /> b = pow(b, N);<br /> return lst( b * Q, b * R);<br />}<br /></pre><br /><br />Well, testing both algorithm against the quo and rem that do the same computation in GiNaC, we have this: <br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg45ytOZG91lYFlbbhsCceXoa1gKQaflkxeOZxBLB-qWAmp682EIeF11S_RTWqXbVxy1v7XXFNCKSLEHPfZhU9JsRrVx4jcFjTQDbizA9xswIzowBJPq08EQlDSbChckqFYuqFD/s1600-h/div.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 273px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg45ytOZG91lYFlbbhsCceXoa1gKQaflkxeOZxBLB-qWAmp682EIeF11S_RTWqXbVxy1v7XXFNCKSLEHPfZhU9JsRrVx4jcFjTQDbizA9xswIzowBJPq08EQlDSbChckqFYuqFD/s400/div.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5369332276132493346" /></a><br /><br />The test is a division between two polynomials of the same n degree randomly generated, in x-axis is n and in y-axis is ellapsed time of the compute code in sec.<br /><br /><pre name="code" class="cpp"><br />int main()<br />{<br /> symbol x("x");<br /> int i = 0;<br /> ex a=0, b=0;<br /><br /> clock_t s, e;<br /> double t1,t2, t3, t4, t5;<br /><br /> for(int n = 1; n < 100000 ; n += 1000)<br /> {<br /> srand ( time(NULL) );<br /><br /> for(; i < n; i++)<br /> {<br /> a += (rand() % 200 - 100) * pow(x,i);<br /> b += (rand() % 200 - 100) * pow(x,i);<br /> }<br /><br /> s = clock();<br /> PolyDivide(a,b,x);<br /> e = clock();<br /> t1 = (e-s);<br /><br /> s = clock();<br /> PolyPseudoDivide(a,b,x);<br /> e = clock();<br /> t2 = (e-s);<br /><br /> s = clock();<br /> quo(a,b,x); rem(a,b,x);<br /> e = clock();<br /> t3 = (e-s);<br /><br /> ex q;<br /> s = clock();<br /> q = quo(a,b,x);a - b*q;<br /> e = clock();<br /> t4 = (e-s);<br /><br /> ex r;<br /> s = clock();<br /> r = rem(a,b,x);(a-r)/b;<br /> e = clock();<br /> t5 = (e-s);<br /><br /><br /> t1 /= CLOCKS_PER_SEC;<br /> t2 /= CLOCKS_PER_SEC;<br /> t3 /= CLOCKS_PER_SEC;<br /> t4 /= CLOCKS_PER_SEC;<br /> t5 /= CLOCKS_PER_SEC;<br /><br /> cout << n << " " << t1 << " " << t2 << " " << t3 << " " << t4 << " " << t5 << endl;<br /> }<br /><br /> return 0;<br />}<br /></pre>Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-51735297967935711962009-07-22T19:11:00.000-07:002009-07-22T21:16:25.999-07:00Create a new toolbox for Scilab (II)Now i gonna follow the instructions at: http://www.scilab.org/contrib/index_contrib.php?page=toolbox_guide<br /><br />1) First i need to create all the files needed to the toolbox:<br /><br /><pre name="code" class="bash"><br />toolbox$ cd scilab/scilab/contrib/<br />toolbox/scilab/scilab/contrib$ mkdir symbolic<br />toolbox/scilab/scilab/contrib$ cd symbolic/<br />toolbox/scilab/scilab/contrib/symbolic$ mkdir macros src sci_gateway help etc unit_tests demos includes<br />toolbox/scilab/scilab/contrib/symbolic$ touch readme.txt builder.sce loader.sce license.txt<br /></pre><br /><br />2) Macros, well, basically i only have one macro at the symbolic module, but i gonna test the macro at the instructions, so:<br /><br /><pre name="code" class="bash"><br />toolbox/scilab/scilab/contrib/symbolic$ cd macros/<br />toolbox/scilab/scilab/contrib/symbolic/macros$ cat << EOF > foo1.sci<br />function [X]=foo1(A)<br /> // This function returns the positive components of the A diagonal<br /><br /> // Check the type and the size of A<br /> if type(A)<>1 then<br /> error("type of input argument must be a double");<br /> end<br /> if size(A,1)<>size(A,2) then<br /> error("input argument must be a square matrix");<br /> end<br /> //Extraction of the positive components<br /> X=[];<br /> for i=1:size(A,1)<br /> if A(i,i)>0 then<br /> X($+1)=A(i,i);<br /> end<br /> end<br />endfunction<br /><br />EOF<br />toolbox/scilab/scilab/contrib/symbolic/macros$ cat << EOF > buildmacros.sce<br />mode(-1)<br />toolboxname='symbolic'<br />pathB=get_absolute_file_path('buildmacros.sce')<br />disp('Building macros in ' +pathB)<br />genlib(toolboxname+'lib',pathB,%t)<br />clear pathB genlib toolboxname<br /><br />EOF<br />toolbox/scilab/scilab/contrib/symbolic/macros$ cat << EOF > loadmacros.sce<br />mode(-1)<br />pathL=get_absolute_file_path('loadmacros.sce')<br />disp('Loading macros in ' +pathL)<br />load(pathL+'/lib')<br />clear pathL<br /><br />EOF<br /></pre><br /><br />3) We're going to create some primitives now, basically is like the module, so, there is a sci_gateway path and a src path, in the first we define the gateways to our functions, and in the second we write the main code of the primitives.<br /><br /><pre name="code" class="bash"><br />toolbox/scilab/scilab/contrib/symbolic$ cd src/<br />toolbox/scilab/scilab/contrib/symbolic/src$ cat << EOF > vectsum.c<br />void vectsum(int n, double * a, double * b, double * y)<br />{<br /> int k;<br /> for (k = 0; k < n; ++k) <br /> y[k] = a[k] + b[k];<br />}<br /><br />EOF<br />jcardona@terminus:~/stuff/personal/symbolic/main/toolbox/scilab/scilab/contrib/symbolic/src$ cd ..<br />toolbox/scilab/scilab/contrib/symbolic$ cd sci_gateway/<br />toolbox/scilab/scilab/contrib/symbolic/sci_gateway$ cat << EOF > sci_sumab.c<br />#include "stack-c.h"<br />extern int vectsum(int n, double * a, double * b, double * y); <br /><br />void sci_sumab(char *fname){ <br />int l1, m1, n1, l2, m2, n2, l3, n; <br /><br />/* 1 - Check the number of inputs/outputs arguments */ <br />int minlhs=1, maxlhs=1, minrhs=2, maxrhs=2; <br />CheckRhs(minrhs,maxrhs) ; <br />CheckLhs(minlhs,maxlhs) ; <br /><br />/* 2 - Check inputs arguments type, and get the size<br /> and the address in the Scilab stack of the inputs<br /> arguments<br />*/<br />GetRhsVar(1, "d", &m1, &n1, &l1);<br />GetRhsVar(2, "d", &m2, &n2, &l2);<br /><br />/* 3 - Check that the inputs arguments have the same size */<br />/* it's possible to use the chekdims and getscalar<br /> functions to make these checks<br />*/ <br />n=m2*n2; <br />if( n1!=n2 || m1!=m2) <br />{<br /> cerro("inputs arguments must have the same size"); <br /> return 0; <br />}<br />if(n1!=0 && m1!=0) <br /> if(n1!=1 && m1!=1) <br /> {<br /> cerro("inputs arguments must be vectors"); <br /> return(0); <br /> }<br /> <br /><br />/* 4 - Create a new variable corresponding to the output argument */ <br />CreateVar(3,"d",&m2,&n2,&l3); <br /><br />/* 5 -call vectsum routine: returns in stk(l3) the sum of a and b*/<br />vectsum(n,stk(l1),stk(l2),stk(l3)); <br /><br />/* 6 - Specif ouput argument */ <br />LhsVar(1) = 3; <br />return 0;<br />}<br /><br />EOF<br /><br /></pre><br /><br />The builder for the primitives, we need a buildsrc.sce and a buildsci_gateway.sce, in the respective path. The first one creates a shared library that is linked to the second shared library (the one of the gateway).<br /><br /><pre name="code" class="bash"><br />toolbox/scilab/scilab/contrib/symbolic/src$ cat << EOF > buildsrc.sce<br />//ilib_for_link('symbolicsrc',['fun1.o','fun2.o','vectsum.o'],[],"c")<br />ilib_for_link('symbolicsrc',['vectsum.o'],[],"c")<br /><br />EOF<br />toolbox/scilab/scilab/contrib/symbolic/sci_gateway$ cat << EOF >buildsci_gateway.sce<br />// must be run from this directory<br />ilib_name = 'libsymbolic' // interface library name<br />//files = ['sci_fun.o','sci_sumab.o']; // objects files<br />files = ['sci_sumab.o']; // objects files<br />libs = ["../src/libsymbolicsrc"] // other libs needed for linking<br />//table = [ /*'fun', 'sci_fun';*/<br />table = ['sumab','sci_sumab']; // table of (scilab_name,interface-name)<br />// do not modify below<br />ilib_build(ilib_name,table,files,libs)<br /><br />EOF<br /><br /></pre><br /><br />4) The help files are located at the help path with a xml format, and a dtd defined by scilab, we only add a template for the files:<br /><br /><pre name="code" class="bash"><br />toolbox/scilab/scilab/contrib/symbolic/help$ cat << EOF > sumab.xml <br /><?xml version="1.0" encoding="UTF-8"?><br /><refentry version="5.0-subset Scilab" xml:id="sumab" xml:lang="en"<br /> xmlns="http://docbook.org/ns/docbook"<br /> xmlns:xlink="http://www.w3.org/1999/xlink"<br /> xmlns:svg="http://www.w3.org/2000/svg"<br /> xmlns:ns3="http://www.w3.org/1999/xhtml"<br /> xmlns:mml="http://www.w3.org/1998/Math/MathML"<br /> xmlns:db="http://docbook.org/ns/docbook"><br /> <info><br /> <pubdate>$LastChangedDate: 2008-03-26 09:50:39 +0100 (mer., 26 mars 2008)$</pubdate><br /> </info><br /><br /> <refnamediv><br /> <refname>sumab</refname><br /><br /> <refpurpose>Purpose</refpurpose><br /> </refnamediv><br /><br /> <refsynopsisdiv><br /> <title>Calling Sequence</title><br /><br /> <synopsis>sequence</synopsis><br /> </refsynopsisdiv><br /><br /> <refsection><br /> <title>Description</title><br /><br /> <para>Do something</para><br /><br /> <para>Add here a paragraph of the function description </para><br /> </refsection><br /><br /> <refsection><br /> <title>Examples</title><br /><br /> <programlisting role="example">exmaple</programlisting><br /> </refsection><br /><br /> <refsection><br /> <title>Authors</title><br /><br /> <simplelist type="vert"><br /> <member>YOUR NAME</member><br /> </simplelist><br /> </refsection><br /></refentry><br /><br />EOF<br />toolbox/scilab/scilab/contrib/symbolic/help$ cat sumab.xml | sed -e 's?sumab?foo1?' > foo1.xml<br />toolbox/scilab/scilab/contrib/symbolic/help$ cat << EOF > buildhelp.sce<br />mode(-1) //force silent execution<br />path=get_absolute_file_path('buildhelp.sce');//get the absolute path of this file<br />add_help_chapter("Symbolic",path);//add help chapter<br />xmltohtml(path,"Symbolic")<br />//clear the variable stack<br />clear path add_help_chapter get_absolute_file_path <br /><br />EOF<br />toolbox/scilab/scilab/contrib/symbolic/help$ cat << EOF > loadhelp.sce<br />mode(-1) //force silent execution<br />path=get_absolute_file_path('loadhelp.sce');//get the absolute path of this file<br />add_help_chapter("Symbolic",path);//add help chapter<br />clear path add_help_chapter get_absolute_file_<br /><br />EOF<br /></pre><br /><br />5) Finally we set the global builder and loader:<br /><br /><pre name="code" class="bash"><br />toolbox/scilab/scilab/contrib/symbolic$ cat << EOF > builder.sce<br />mode(-1);<br />mainpathB=get_absolute_file_path('builder.sce');<br />chdir(mainpathB);<br />if isdir('src') then<br />chdir('src');<br />exec('buildsrc.sce');<br />chdir('..');<br />end<br />if isdir('sci_gateway') then<br />chdir('sci_gateway');<br />exec('buildsci_gateway.sce');<br />chdir('..');<br />end<br />if isdir('macros') then<br />chdir('macros');<br />exec('buildmacros.sce');<br />chdir('..');<br />end<br />if isdir('help') then<br />chdir('help');<br />exec('buildhelp.sce');<br />chdir('..');<br />end<br />clear mainpathB<br /><br />EOF<br />toolbox/scilab/scilab/contrib/symbolic$ cat << EOF > loader.sce<br />mode(-1);<br />mainpathL=get_absolute_file_path('loader.sce');<br />chdir(mainpathL);<br />if isdir('sci_gateway') then<br />chdir('sci_gateway');<br />exec('loader.sce');<br />chdir('..');<br />end<br />if isdir('macros') then<br />chdir('macros');<br />exec('loadmacros.sce');<br />chdir('..');<br />end<br />if isdir('help') then<br />chdir('help');<br />exec('loadhelp.sce');<br />chdir('..');<br />end<br />clear mainpathL<br /><br />EOF<br /></pre><br /><br />6) Build it at scilab:<br /><br /><pre name="code" class="bash"><br />toolbox/scilab/scilab$ bin/scilab<br /><br />-->exec("contrib/symbolic/builder.sce")<br /> <br />-->mode(-1);<br /> Generate a loader file<br /> Generate a Makefile<br /> ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR<br /> ilib_gen_Make: Copy vectsum.c to TMPDIR<br /> ilib_gen_Make: Modification of the Makefile in TMPDIR.<br /> Running the Makefile<br /> Generate a cleaner file<br /> ans =<br /> <br /> libsymbolicsrc.so <br /> ilib_name =<br /> <br /> libsymbolic <br /> libs =<br /> <br /> ../src/libsymbolicsrc <br /> Generate a gateway file<br /> Generate a loader file<br /> Generate a Makefile<br /> ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR<br /> ilib_gen_Make: Copy sci_sumab.c to TMPDIR<br /> ilib_gen_Make: Copy libsymbolic.c to TMPDIR<br /> ilib_gen_Make: Modification of the Makefile in TMPDIR.<br /> Running the makefile<br /> Generate a cleaner file<br /> <br /> Building macros in /home/jcardona/stuff/personal/symbolic/main/toolbox/scilab/scilab/contrib/symbolic/macros/ <br /><br />Building the master document:<br /> SCI/contrib/symbolic/help<br /><br />Building the manual file [html] in SCI/contrib/symbolic/help. (Please wait building ... this can take a while)<br />Warning : redefining function: get_absolute_file_path . Use funcprot(0) to avoid this message<br /><br />-->exec("contrib/symbolic/loader.sce")<br /> <br />-->mode(-1);<br />Shared archive loaded.<br />Link done.<br />Shared archive loaded.<br />Link done.<br /> <br /> Loading macros in /home/jcardona/stuff/personal/symbolic/main/toolbox/scilab/scilab/contrib/symbolic/macros/ <br /> <br />-->sumab(1,2)<br /> ans =<br /> <br /> 3. <br /> <br />-->sumab(2,2)<br /> ans =<br /> <br /> 4.<br /></pre><br /><br />We have then a brand new toolbox enjoy summing.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-61604919379409046862009-07-21T19:23:00.000-07:002009-07-22T07:20:19.995-07:00Create a new toolbox for Scilab (I)As i have to change my symbolic module to a symbolic toolbox, i want to write this to use as a future reference.<br /><br />1) Get Scilab:<br /><br /><pre name="code" class="bash"><br />$ mkdir toolbox<br />$ cd toolbox/<br />toolbox$ git clone git://git.scilab.org/scilab<br /></pre><br /><br />2) First compilation:<br /><br /><pre name="code" class="bash"><br /><br />toolbox$ cd scilab/scilab<br /><br />toolbox/scilab/scilab$ ./configure<br />...<br />checking hdf5.h usability... no<br />checking hdf5.h presence... no<br />checking for hdf5.h... no<br />configure: error: Cannot find headers (hdf5.h) of the library HDF5. Please install the dev package<br /><br /></pre><br /><br />3) HDF5 Headers:<br /><pre name="code" class="bash"><br />sudo aptitude install libhdf5-serial-dev<br /></pre><br /><br /><br />4) Installing JHDF5 :<br /><br /><pre name="code" class="bash"><br />wget http://www.hdfgroup.org/ftp/HDF5/hdf-java/src/hdf-java-2.5-src.tar<br />tar -xvf hdf-java-2.5-src.tar<br />cd hdf-java/<br />./configure --with-jdk=/usr/lib/jvm/java-6-sun-1.6.0.14/include/,/usr/lib/jvm/java-6-sun-1.6.0.14/lib/<br />make<br />sudo mkdir -p /usr/share/java/jar<br />sudo cp lib/jhdf5.jar /usr/share/java/jar<br /></pre><br /><br />5) Configuring again:<br /><br /><pre name="code" class="bash"><br />toolbox/scilab/scilab$ ./configure<br />toolbox/scilab/scilab$ make<br />toolbox/scilab/scilab$ bin/scilab<br /></pre><br /><br />Well, we now have our scilab base.<br />We have to set all the toolboxes files, but that will be tonight.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-68619137043365423042009-05-13T21:33:00.000-07:002009-05-13T21:39:46.966-07:00Lock free programminghttp://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms<br />http://en.wikipedia.org/wiki/Compare-and-swap<br /><br />http://www.google.com/search?hl=en&client=iceweasel-a&rls=org.debian%3Aen-US%3Aunofficial&q=lock+free+&btnG=SearchJorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-64217188349077860712009-05-13T18:49:00.000-07:002009-05-13T18:53:38.613-07:00Jack en gumstix.MMM, necesito un framework de simulacion por bloques que este ligado la kernel, se me vino a la cabeza jack y su forma de pasar datos entre plugins, y simplemente vi esto en unos <a href="http://lad.linuxaudio.org/events/2003_zkm/slides/paul_davis-jack/title.html">slides</a>:<br /><br />Although not a requirement, Jack should support any streaming data type, not just audio. <br /><br />Podria ser una buena opcion meter jack en el gumstix y crear los bloques de control como si fueran plugins y el paso de datos serian rapidito, el llamaod a los codigos de los bloques. Suena interesante la cosa. Veremos que sale.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-63335946390119885882009-04-28T20:23:00.001-07:002009-04-28T22:31:36.040-07:00Drivers en linux (II)Ahora crearemos un dispositivo de caracteres en /dev/algo, para esto debemos definir cuatro nuevas funciones: para abrir y cerrar el dispositivo, y para leer y escribirlo. Hay mas operaciones, pero con esas es suficiente por ahora (http://www.linuxtopia.org/online_books/linux_kernel/linux_kernel_module_programming_2.6/x569.html).<br /><br />El archivo test.h queda asi:<br /><pre name="code" class="C"><br />#ifndef _TEST_SPI_H_<br />#define _TEST_SPI_H_<br /><br />#define DEVICE_NAME "test-spi"<br /><br />MODULE_AUTHOR("Jorge Eduardo Cardona <jorgeecardona@gmail.com>");<br />MODULE_DESCRIPTION("SPI test driver.");<br />MODULE_LICENSE("GPL");<br /><br />// Character device functions.<br />static int this_open(struct inode *inode, struct file *file);<br />static int this_release(struct inode *inode, struct file *file);<br />static ssize_t this_read(struct file *file, char __user *buffer, size_t len, loff_t *offset);<br />static ssize_t this_write(struct file *file, const char __user *buffer, size_t len, loff_t *offset);<br /><br />// File Operations structure.<br />struct file_operations this_fops = {<br /> .open = this_open,<br /> .release = this_release,<br /> .read = this_read,<br /> .write = this_write<br />};<br /><br />// Linux module functions.<br />static int __init this_init(void);<br />static void __exit this_exit(void);<br />module_init(this_init);<br />module_exit(this_exit);<br /><br />#endif<br /></pre><br /><br /><br />Para crear el dispositivo de caracteres debemos llamar a la funcion: register_chrdev (http://kerneltrap.org/man/linux/man9/register_chrdev.9)(http://www.silicontao.com/ProgrammingGuide/GNU_function_list/register_chrdev.html)<br /><pre name="code" class="C"><br />#include <linux/module.h><br />#include <linux/fs.h><br />#include <linux/err.h><br /><br /><br />#include "test.h"<br /><br />// Global data<br />static int this_major;<br /><br /><br />// Function that is called every time we try to open a device.<br />static int this_open(struct inode *inode, struct file *file)<br />{<br /> printk(DEVICE_NAME": Open device.\n");<br /> return 0;<br />}<br /><br />// Function that is called when we close a device.<br />static int this_release(struct inode *inode, struct file *file)<br />{<br /> printk(DEVICE_NAME": Close device.\n");<br /> return 0;<br />}<br /><br />// Function that is called when we read from a device.<br />static ssize_t this_read(struct file *file, char __user *buffer, size_t len, loff_t *offset)<br />{<br /> printk(DEVICE_NAME": Read device.\n");<br /> return 0;<br />}<br /><br />// Function that is called when we write to a device.<br />static ssize_t this_write(struct file *file, const char __user *buffer, size_t len, loff_t *offset)<br />{<br /> printk(DEVICE_NAME": Write device.\n");<br /> return 0;<br />}<br /><br />// Function that is called when we load the module.<br />static int __init this_init(void)<br />{<br /> int ret;<br /><br /> printk(DEVICE_NAME ": Init.\n");<br /><br /> // Register char device: 0 for dynamically allocation of the major number.<br /> ret = register_chrdev(0, DEVICE_NAME, &this_fops);<br /> if (~IS_ERR_VALUE(ret))<br /> {<br /> printk(DEVICE_NAME ": Character device registered, with major=%d.\n",ret);<br /> this_major = ret;<br /><br /> return 0;<br /> }<br /><br /> unregister_chrdev(this_major, DEVICE_NAME);<br /> printk(DEVICE_NAME ": Character device unregistered.\n");<br /><br /> return ret;<br />}<br /><br />// Function that is called when we remove the module.<br />static void __exit this_exit(void)<br />{<br /> unregister_chrdev(this_major, DEVICE_NAME);<br /> printk(DEVICE_NAME ": Character device unregistered.\n");<br /> printk(DEVICE_NAME ": Exit.\n");<br />}<br /></pre><br />(http://tomoyo.sourceforge.jp/cgi-bin/lxr/ident?i=IS_ERR_VALUE)<br /><br />Bueno, igual que antes, configuramos, compilamos y tenemos:<br /><pre name="code" class="Bash"><br />root@gumstix-custom-connex:~$ modprobe test<br />root@gumstix-custom-connex:~$ dmesg | grep "test-spi"<br /><4>test-spi: Init.<br /><4>test-spi: Character device registered, with major=254.<br />root@gumstix-custom-connex:~$ mknod /dev/test c 254 0<br />root@gumstix-custom-connex:~$ cat /dev/test <br />root@gumstix-custom-connex:~$ dd bs=1 count=0 if=/dev/zero of=/dev/test<br />0+0 records in<br />0+0 records out<br />root@gumstix-custom-connex:~$ echo "ja" > /dev/test<br /><br />root@gumstix-custom-connex:~$ rmmod test<br />root@gumstix-custom-connex:~$ dmesg | grep "test-spi"<br /><4>test-spi: Init.<br /><4>test-spi: Character device registered, with major=254.<br /><4>test-spi: Open device.<br /><4>test-spi: Read device.<br /><4>test-spi: Close device.<br /><4>test-spi: Open device.<br /><4>test-spi: Close device.<br /><4>test-spi: Open device.<br /><4>test-spi: Write device.<br /><4>test-spi: Write device.<br /><4>test-spi: Write device.<br /><4>test-spi: Write device.<br /><4>test-spi: Write device.<br /><4>test-spi: Write device.<br /><4>test-spi: Write device.<br /><4>test-spi: Write device.<br /><4>test-spi: Write device.<br /><4>test-spi: Write device.<br /><4>test-spi: Close device.<br /><4>test-spi: Character device unregistered.<br /><4>test-spi: Exit.<br />root@gumstix-custom-connex:~$ <br /></pre><br /><br />Los varios mensajes de Write se deben a que retornamos 0 esto quiere decir que no escribimos ningun caracter y la funcion es llamada hasta que vacie el buffer, pero aqui toca matarla con un Ctrl-C.<br /><br />Bueno, un paso mas.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com1tag:blogger.com,1999:blog-34133079.post-34497163841065541662009-04-28T07:52:00.000-07:002009-04-28T20:22:04.052-07:00Drivers en linux (I)Bueno iba a hacer esto en un solo post pero por partes es mejor, primero lo básico, cargar y bajar el modulo. En mi caso necesito un modulo para SPI, entonces lo ubico en drivers/spi/test.c<br /><br />Comenzando con lo basico, entrar y bajar el modulo.<br /><br /><span style="font-weight:bold;">test.c</span><br /><pre name="code" class="C" ><br />#include <linux/module.h><br />#include "test.h"<br /><br />static int __init this_init(void)<br />{<br /> // Initialize module.<br /><br /> printk(DEVICE_NAME ": Init.\n");<br />}<br /><br />static void __exit this_exit(void)<br />{<br /> // Exit module.<br /><br /> printk(DEVICE_NAME ": Exit.\n");<br />}<br /></pre><br /><br /><span style="font-weight:bold;">test.h</span><br /><pre name="code" class="C"><br />#ifndef _TEST_SPI_H_<br />#define _TEST_SPI_H_<br /><br />#define DEVICE_NAME "test-spi"<br /><br />MODULE_AUTHOR("Jorge Eduardo Cardona <jorgeecardona@gmail.com>");<br />MODULE_DESCRIPTION("SPI test driver.");<br />MODULE_LICENSE("GPL");<br /><br />// Linux module functions.<br />static int __init this_init(void);<br />static void __exit this_exit(void);<br />module_init(this_init);<br />module_exit(this_exit);<br /><br />#endif<br /></pre><br /><br />Tenemos que manipular dos archivos mas: Kconfig y Makefile, ambos en la misma carpeta:<br /><br /><span style="font-weight:bold;">Kconfig</span><br /><pre name="code" class="C"><br />.<br />.<br />.<br />config SPI_TEST<br /> tristate "Test SPI driver."<br /> depends on SPI_MASTER && EXPERIMENTAL<br /> help<br /> Test SPI driver.<br />.<br />.<br />.<br /></pre><br /><br /><span style="font-weight:bold;">Makefile</span><br /><pre name="code" class="Bash"><br />.<br />.<br />.<br />obj-$(CONFIG_SPI_TEST) += test.o<br />.<br />.<br />.<br /></pre><br /><br />Al configurar el kernel nos saldra la opcion, la seleccionamos y podremos hacer esto:<br /><pre name="code" class="Bash"><br />root@gumstix-custom-connex:~$ modprobe test<br />root@gumstix-custom-connex:~$ dmesg | tail -n1<br /><4>; test-spi: Init.<br />root@gumstix-custom-connex:~$ rmmod test<br />root@gumstix-custom-connex:~$ dmesg | tail -n1<br /><4> test-spi: Exit.<br />root@gumstix-custom-connex:~$ <br /></pre><br /><br />Primer paso listo.Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0tag:blogger.com,1999:blog-34133079.post-22331916482009634612009-04-15T15:12:00.001-07:002009-04-15T16:31:01.713-07:00Contando racionales.Un numero racional es todo aquel que puede ser escrito de la forma:<br /><br />racional = a/b : siendo a y b numeros enteros.<br /><br />Usando el metodo como Georg Ferdinand Ludwig Philipp Cantor demostro que los racionales son contables podemos crear un pequeñito programa para sacar el i-esimo racional de la tabla de cantor:<br /><br /><pre name="code" class="Python"><br />from math import sqrt<br /><br />def rational(i):<br /> b = int((sqrt(1+8*i)-1)/2)<br /> n = i - (b**2 + b)/2 + 1<br /> d = b + 2 - n<br /><br /> return (n,d)<br /><br /><br />for i in xrange(100):<br /> (n,d) = rational(i)<br /><br /> print "(%d) %d/%d \t= %f"%(i,n,d,float(n)/float(d))<br /><br /></pre><br /><br />Bueno, La tabla de Cantor es sencilla, el numerador aumenta columna a columna desde 1 hasta aleph_0 y el denumenador fila a fila de 1 a aleph_0, de esta forma todos los nuemros racionales son cubiertos por la tabla, y por tanto son contables, se les puede asociar uno a uno un elemento de los enteros.<br /><br />La tabla:<br /><pre><br />1/1 2/1 3/1 4/1 5/1 6/1 7/1 8/1 9/1 ...<br />1/2 2/2 3/2 4/2 5/2 6/2 7/2 8/2 9/2 ...<br />1/3 2/3 3/3 4/3 5/3 6/3 7/3 8/3 9/3 ...<br />1/4 2/4 3/4 4/4 5/4 6/4 7/4 8/4 9/4 ...<br />1/5 2/5 3/5 4/5 5/5 6/5 7/5 8/5 9/5 ...<br />1/6 2/6 3/6 4/6 5/6 6/6 7/6 8/6 9/6 ...<br />1/7 2/7 3/7 4/7 5/7 6/7 7/7 8/7 9/7 ...<br />1/8 2/8 3/8 4/8 5/8 6/8 7/8 8/8 9/8 ...<br />1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9 ...<br /></pre><br /><br />Y el conteo:<br /><pre><br />0 2 5 9 14 20 27 35 44 ...<br />1 4 8 13 19 26 34 43 53 ...<br />3 7 12 18 25 33 42 52 ... <br />6 11 17 24 32 41 51 ...<br />10 16 23 31 40 50 ...<br />15 22 30 39 49 ... <br />21 29 38 48 ... <br />28 37 47 ...<br />36 46 ...<br />45 ...<br />...<br /></pre><br /><br />Resultado de la ejecucion del codigo:<br /><pre><br />(0) 1/1 = 1.000000<br />(1) 1/2 = 0.500000<br />(2) 2/1 = 2.000000<br />(3) 1/3 = 0.333333<br />(4) 2/2 = 1.000000<br />(5) 3/1 = 3.000000<br />(6) 1/4 = 0.250000<br />(7) 2/3 = 0.666667<br />(8) 3/2 = 1.500000<br />(9) 4/1 = 4.000000<br />(10) 1/5 = 0.200000<br />(11) 2/4 = 0.500000<br />(12) 3/3 = 1.000000<br />(13) 4/2 = 2.000000<br />(14) 5/1 = 5.000000<br />(15) 1/6 = 0.166667<br />(16) 2/5 = 0.400000<br />(17) 3/4 = 0.750000<br />(18) 4/3 = 1.333333<br />(19) 5/2 = 2.500000<br />(20) 6/1 = 6.000000<br />(21) 1/7 = 0.142857<br />(22) 2/6 = 0.333333<br />(23) 3/5 = 0.600000<br />(24) 4/4 = 1.000000<br />(25) 5/3 = 1.666667<br />(26) 6/2 = 3.000000<br />(27) 7/1 = 7.000000<br />(28) 1/8 = 0.125000<br />(29) 2/7 = 0.285714<br />(30) 3/6 = 0.500000<br />(31) 4/5 = 0.800000<br />(32) 5/4 = 1.250000<br />(33) 6/3 = 2.000000<br />(34) 7/2 = 3.500000<br />(35) 8/1 = 8.000000<br />(36) 1/9 = 0.111111<br />(37) 2/8 = 0.250000<br />(38) 3/7 = 0.428571<br />(39) 4/6 = 0.666667<br />(40) 5/5 = 1.000000<br />(41) 6/4 = 1.500000<br />(42) 7/3 = 2.333333<br />(43) 8/2 = 4.000000<br />(44) 9/1 = 9.000000<br />(45) 1/10 = 0.100000<br />(46) 2/9 = 0.222222<br />(47) 3/8 = 0.375000<br />(48) 4/7 = 0.571429<br />(49) 5/6 = 0.833333<br />(50) 6/5 = 1.200000<br />(51) 7/4 = 1.750000<br />(52) 8/3 = 2.666667<br />(53) 9/2 = 4.500000<br />(54) 10/1 = 10.000000<br />(55) 1/11 = 0.090909<br />(56) 2/10 = 0.200000<br />(57) 3/9 = 0.333333<br />(58) 4/8 = 0.500000<br />(59) 5/7 = 0.714286<br />(60) 6/6 = 1.000000<br />(61) 7/5 = 1.400000<br />(62) 8/4 = 2.000000<br />(63) 9/3 = 3.000000<br />(64) 10/2 = 5.000000<br />(65) 11/1 = 11.000000<br />(66) 1/12 = 0.083333<br />(67) 2/11 = 0.181818<br />(68) 3/10 = 0.300000<br />(69) 4/9 = 0.444444<br />(70) 5/8 = 0.625000<br />(71) 6/7 = 0.857143<br />(72) 7/6 = 1.166667<br />(73) 8/5 = 1.600000<br />(74) 9/4 = 2.250000<br />(75) 10/3 = 3.333333<br />(76) 11/2 = 5.500000<br />(77) 12/1 = 12.000000<br />(78) 1/13 = 0.076923<br />(79) 2/12 = 0.166667<br />(80) 3/11 = 0.272727<br />(81) 4/10 = 0.400000<br />(82) 5/9 = 0.555556<br />(83) 6/8 = 0.750000<br />(84) 7/7 = 1.000000<br />(85) 8/6 = 1.333333<br />(86) 9/5 = 1.800000<br />(87) 10/4 = 2.500000<br />(88) 11/3 = 3.666667<br />(89) 12/2 = 6.000000<br />(90) 13/1 = 13.000000<br />(91) 1/14 = 0.071429<br />(92) 2/13 = 0.153846<br />(93) 3/12 = 0.250000<br />(94) 4/11 = 0.363636<br />(95) 5/10 = 0.500000<br />(96) 6/9 = 0.666667<br />(97) 7/8 = 0.875000<br />(98) 8/7 = 1.142857<br />(99) 9/6 = 1.500000<br /></pre>Jorge Eduardo Cardonahttp://www.blogger.com/profile/17366392704306249165noreply@blogger.com0