Archive

Posts Tagged ‘Latex’

My first try creating a bash script

January 30, 2016 2 comments

I am a ubuntu user, but sometimes I also use windows, mainly because my computer in the office is using windows. So, I use both ubuntu and windows. Even, my laptop has both windows and ubuntu. I tried to get rid of windows once, and installed wine to use windows application in my ubuntu. But it runs very slowly and it’s killing me and in the end, I came back to reinstall windows. I mainly use ubuntu for my research. The softwares I use for my research are auto, python, dstool, latex, xfig which run smoothly in ubuntu, even though python and latex can also be installed and run smoothly on windows machine. On the other hand, I use windows to do some regular activities such as browsing the internet, watching movies, checking my email, creating an office documents etc. All of which can be done in ubuntu as well. But there are activities that I must use windows, I sometimes need to use matlab and sometimes I like to play a game that only runs in windows. These two things are the main reason I still come back to use windows. Recently, I learn python so I am now trying to less use matlab.

That is just a background and my main point here is about bash scripting. After a few years using ubuntu, I have not created any bash script. Today, finally I learn to create one script. I created a script to automate my boring routine. When I write a paper, I need some illustrations. I mostly use xfig to create some mathematical images and to be able to use \LaTeX in the figure I need to convert it to an eps file. The produced eps file will be then converted to a pdf file as it is perfectly compatible to my pdflatex command. But before that, I need to crop the resulted pdf file in order to remove white space around the image. Suppose the name of my xfig file is spam.fig. I then write a series of command.

figtex2eps spam.fig
ps2pdf spam.eps
pdfcrop spam.pdf

I want to write a script that do all the above automatically. Thus I created the following script.

#!/bin/bash
# Converts a .fig-file (xfig file) to a .eps-file by using a built-in function figtex2eps
# and then convert it to a .pdf file by using a built-in function ps2pdf
# and finally convert it to a cropped pdf file by using a built-in function pdfcrop
#
# ivanky saputra https://ivanky.wordpress.com
#
# credit to :
# $ /home/abel/c/berland/etc/cvsrepository/figtex2eps/prog/figtex2eps $
# $ ps2pdf in ubuntu $
# $ pdfcrop in ubuntu $
echo "We are going to change the following $1.fig to a cropped pdf file"
function quit {
exit
}
if [$1 == ""];
then
    echo "no files given";
    quit
else
    echo "Processing $1.fig............";
    figtex2eps $1.fig
    ps2pdf $1.eps
    pdfcrop $1.pdf
    echo "Done";
fi

As someone has said that it is better to share your code and data openly as we as human are idiots and will make mistakes, please give me any suggestion to improve mine.

The solvability condition of A x = b when A is not a square matrix

March 19, 2010 5 comments

In an elementary linear algebra course, we learned the solvability condition of the linear system

A \mathbf{x} =\mathbf{ b}

where A is an n \times n matrix and \mathbf{x}, \mathbf{b} are n \times 1 vectors.

To mention a few, the followings are the solvability conditions (equivalent conditions) such that the linear system above has a solution:

  1. determinant of A is not zero
  2. rank of A is full
  3. all eigenvalues of A are non zero
  4. the vector columns (also rows) are independent
  5. A has an inverse
  6. et cetera

However, I would like to discuss the case when either (#) A is not a square matrix or
(##) the rank of A is not full (< $latex  n$).

There is actually a condition such that the linear system A \mathbf{x} = \mathbf{b} has a solution whenever we have either (#) or (##). The solvability condition is

\mathbf {b} \in Col(A).

The thing is this condition is not applicable to most problems I have ever had. For instances, I bumped into the following problem.

Let A, \mathbf{x}, \mathbf{b} be the following

A=\left(\begin{array}{cc}a_{11} & a_{21} \\a_{12} & a_{22} \\b_{1} &b_{2} \\\end{array}\right)\mathbf{x} = (l_1, l_2)^T and \mathbf{b}=(-a_{11},-a_{22},0)^T. I want to seek a condition such that the linear system A \mathbf{x}=\mathbf{b} is solvable for l_1,l_2. I want to find a condition for a_{ij} and b_i such that there is a solution of l_1, l_2.

The statement \mathbf{b} \in Col(A) did not help me at that time and I look for another implication for this statement that is applicable enough to my problem.

Fundamental Theorem of Orthogonality (see [1])
Let A be any m \times n matrices.  The row space of A is orthogonal to the null space of A.

Proof: Suppose \mathbf{x} is a vector in the nullspace. Then A \mathbf{x} = 0. This equation can be considered as rows of A multiplying \mathbf{x}:

A\mathbf{x} = \left[\begin{array}{ccc}\cdots & row_1 & \cdots \\\cdots & row_2 & \cdots \\ \phantom{a}  & \phantom{a} & \phantom{a} \\ \cdots & row_m & \cdots \\ \end{array}\right]\left[\begin{array}{c} x_1 \\ x_2 \\ \vdots \\ x_n \\ \end{array} \right] = \left[\begin{array}{c} 0 \\ 0 \\ \vdots \\ 0 \\ \end{array}  \right].

We can clearly see that a dot product of row 1 and \mathbf{x} is zero, a dot product of row 2 and \mathbf{x} is zero, and so on. This means that the dot product of every row of A and \mathbf{x} is zero, which means every row of A is orthogonal to \mathbf{x}, which completes the proof.

Corrolary 1
The column space of A is orthogonal to the left null space of A.

Proof: The proof is easy, we just need to consider the transpose of the matrix A.

Going back to our original problem, when the vector \mathbf{b} is in the column space of A, the vector will be orthogonal to any vector in the left null space of A.

Thus, we have the following solvability condition:

Solvability condition of A \mathbf{x} = \mathbf{b} for any matrices A
The linear system A\mathbf{x}=\mathbf{b} has a solution if the dot product of \mathbf{b} and \mathbf{y}_i is zero, where \mathbf{y}_i is the base vector of the left null space of A.

Remark, the above solvability condition is closely related to the linear version of Fredholm solvability condition.

Reference
[1] Strang, G., “Linear Algebra and Its Applications,” Thomson Brooks/Cole

Categories: Justincase Tags: , ,

Installing/Adding new latex packages in ubuntu environment

February 5, 2010 10 comments

Been using ubuntu for a while, here I made some notes on how to add/install new latex packages..

A. If the package in the sty format

1. create a new directory under tex tree

–> sudo mkdir /usr/share/texmf-texlive/tex/latex/<packagename>

2. copy the package inside the new directory

3, run the following command

–> sudo mktexlsr

B. if the package is not the sty format

1. Download <packagename>.ins and <packagename>.dtx (you need both)

2. Run the following command

–> latex  <packagename>.ins

3. You will get the package in the sty format and you can follow instructions in A.

I hope this helps. Thanks to this page.

Categories: Justincase Tags: , ,

LaTeX in my blog

February 21, 2009 13 comments

It might be that I am really outdated. Yesterday, I browsed blogs around the world and found that now we can have LaTeX in our blog. And here I am, trying to figure that out. In the first instance, I just want to write the famous word LaTeX.

I try to write $latex \LaTeX$ and it is now \LaTeX.

A formula can be written in the same way.

\frac{\partial u}{\partial t} + \frac{\partial u}{\partial x} = 0,

while the source code is

$latex \frac{\partial u}{\partial t} + \frac{\partial u}{\partial x} = 0$.

Thanks to Terence Tao’s blog.

Categories: Latex Tags: