Recently I had to edit the sudoers file and I learnt that a dedicated editor for this task exists. The editor is called visudo. On Fedora Core 7 I found it at /usr/sbin/visudo .
Got the job done but am wondering now if there is something like emacssudo. Hmmm !!!
Friday, December 12, 2008
Saturday, November 22, 2008
Plot CSV data files in Gnuplot
To plot a data file that contains data separated with "," use the following at the gnuplot command prompt:
set datafile separator ","
Octave mode in EMACS
To turn on Octave mode in EMACS use this:
It can be done automatically also ... that is for later !
M-x octave-mode
It can be done automatically also ... that is for later !
Saturday, November 1, 2008
Dynamic allocation of a 3d array
#include
using namespace std;
int main()
{
// tensor[numTables][numRows][numCols]
const size_t numTables = 2 ;
const size_t numRows = 3 ;
const size_t numCols = 4 ;
double*** tensor ;
tensor = new double** [numTables];
for(size_t table = 0 ; table < numTables ; ++table)
{
tensor[table] = new double* [numRows];
for(size_t row = 0 ; row < numRows ; ++row)
{
tensor[table][row] = new double [numCols];
}
}
unsigned int count = 1 ;
for(size_t table = 0 ; table < numTables ; ++table)
{
for(size_t row = 0 ; row < numRows ; ++row)
{
for(size_t col = 0 ; col < numCols ; ++col)
{
tensor[table][row][col] = count++;
}
}
}
for(size_t table = 0 ; table < numTables ; ++table)
{
for(size_t row = 0 ; row < numRows ; ++row)
{
for(size_t col = 0 ; col < numCols ; ++col)
{
cout << tensor[table][row][col] << " " ;
}
cout << endl ;
}
cout << endl ;
}
delete [] tensor ;
return 0 ;
}
Thursday, October 30, 2008
find the matching bracket in emacs
Parenthesis balancing in EMACS
An unbalanced parenthesis is one of the most common sources of a programmer's grief. So emacs has a couple of useful features for guarding against them.
You may have noticed that when you are writing C++ code with emacs and type a closing parenthesis, bracket, or brace, the cursor does a little hop to the matching opening character and then returns to its working position. If there is a problem finding the match, emacs flashes the message ``Mismatched parentheses'' in the minibuffer. If the match is so far back in the code that it isn't visible, emacs flashes the context of the matching parenthesis in the minibuffer.
Parenthesis checking can also be done with the mouse. Double left click on any parenthesis, brace, or bracket. Emacs then shows the matching symbol and highlights the code between them.
Source for this information was this.
An unbalanced parenthesis is one of the most common sources of a programmer's grief. So emacs has a couple of useful features for guarding against them.
You may have noticed that when you are writing C++ code with emacs and type a closing parenthesis, bracket, or brace, the cursor does a little hop to the matching opening character and then returns to its working position. If there is a problem finding the match, emacs flashes the message ``Mismatched parentheses'' in the minibuffer. If the match is so far back in the code that it isn't visible, emacs flashes the context of the matching parenthesis in the minibuffer.
Parenthesis checking can also be done with the mouse. Double left click on any parenthesis, brace, or bracket. Emacs then shows the matching symbol and highlights the code between them.
Source for this information was this.
Friday, October 17, 2008
Minimize all open windows simultaneously in Linux
How do I simultaneously minimize all open windows in Linux ?
What is the Linux equivalent of WindowsKey+D in Linux ?
In Gnome its Ctrl+Atl+D.
Source is from this page :D
I would have found this out had I checked
that was the path at least on Fedora Core 7 .
What is the Linux equivalent of WindowsKey+D in Linux ?
In Gnome its Ctrl+Atl+D.
Source is from this page :D
I would have found this out had I checked
System > Preferences > Personal > Keyboard Shortcuts
that was the path at least on Fedora Core 7 .
Monday, October 13, 2008
Emacs Auto-fill mode for multiline comments
Basically I wanted to write multiple lines of comments in .cpp files without having to manually type a double slash ( // ) in front of each comment. While googling for solutions I hit this page which says the following:
So I start googling to find out how to enable the Auto-fill mode and in my search I hit this page which says:
I like the Auto-fill mode :D
I am not too sure if I should turn Auto-fill mode on for all .cpp files ! Guess this post will have to wait.
When Auto Fill mode is on, going past the fill column while typing a comment causes the comment to be continued...
So I start googling to find out how to enable the Auto-fill mode and in my search I hit this page which says:
When Auto Fill mode is turned off, lines continue to the right as you type them. Depending on how you set the value of truncate-lines
, the words you type either disappear off the right side of the screen, or else are shown, in a rather ugly and unreadable manner, as a continuation line on the screen.
I like the Auto-fill mode :D
I am not too sure if I should turn Auto-fill mode on for all .cpp files ! Guess this post will have to wait.
Saturday, October 4, 2008
rename files with same first name but different extentions
The scenario is this. You have a folder/directory with the following files:
basically the ${file##*.} extracts the extensions of the file. On the same note ${file%*.} will extract the first names of the files.
got it from this page :)
a.txt, a.ps, a.pdfand you want to change the file names to
b.txt, b.ps, b.pdfHere is how to do it.
for file in `ls a.*`
do
mv $file b.${file##*.}
done
basically the ${file##*.} extracts the extensions of the file. On the same note ${file%*.} will extract the first names of the files.
got it from this page :)
Thursday, September 25, 2008
ssh'ing to a GNU/Linux machine from WindowsXP
I frequently SSH to a GNU/Linux ( Fedora Core 7 ) machine from a WindowsXP system. I have Xming to import remote display to local system, while I use putty to SSH to the Linux system. Since some days I was facing this strange problem. I could ssh to the linux system fine but could not import the display while launching any gui on the remote system. I got the following error
It turns out that this was occuring because of a corrupt /etc/hosts file on the Linux system. In fact the /etc/hosts file read as below:
God only knows why that was the case. Anyways I fixed the /etc/hosts file to read as below:
127.0.0.1 localhost.localdomain localhost
And wallah it worked fine as before !
I googled for a solution and found on this page. This post did the trick for me. Thanks tomrosenfeld :D
_X11TransSocketINETConnect() can't get address for localhost:6010: Name or service not known
Display localhost:10.0 unavailable, simulating -nw
It turns out that this was occuring because of a corrupt /etc/hosts file on the Linux system. In fact the /etc/hosts file read as below:
::1 localhost6.localdomain6 localhost6
God only knows why that was the case. Anyways I fixed the /etc/hosts file to read as below:
127.0.0.1 localhost.localdomain localhost
And wallah it worked fine as before !
I googled for a solution and found on this page. This post did the trick for me. Thanks tomrosenfeld :D
Friday, September 12, 2008
Real Time Control
Real Time Control ( RTC ) or Hardware in the Loop Simulation
http://www.speedgoat.ch/?gclid=CPe16cmT2JUCFQoNewodRVcwXA
http://www.speedgoat.ch/?gclid=CPe16cmT2JUCFQoNewodRVcwXA
Another problem that might be interesting to solve
Any professional presentation on the Web or T.V. has a host reading the que lines on the monitor and making it look as if the talk was off the cuff or prepared and rehearsed or anything but being read off the screen. I often find myself scrutinizing the eyes of the host to see how well he does the job :P.
Anyways the problem is this how to make it look like they are not reading it off the monitor.
Anyways the problem is this how to make it look like they are not reading it off the monitor.
Monday, August 11, 2008
tips for writing research papers
- Try to include as many results as possible
- Compare your results with results obtained by other authors in the same field.
Tuesday, July 29, 2008
glibc detected double free or corruption
While segmentation fault is the most common error that C/C++ face another one that has been harassing me for some time is as follows ::
glibc detected double free or corruption
This occurs when one tries to release memory that has already been deallocated. One quick and dirty way to get rid of it is as follows :
( thats a zero at the right side of the equal to sign )
and now run the executable, it should run without a problem.
However I am not too sure if this will cause unreliable results or any other sort of problems later. I guess its best to check the code to find out and remedy the error causing this.
Could the following be of any use ?
http://valgrind.org/
See this page to understand how valgrind can help you.
glibc detected double free or corruption
This occurs when one tries to release memory that has already been deallocated. One quick and dirty way to get rid of it is as follows :
$export MALLOC_CHECK_=0
( thats a zero at the right side of the equal to sign )
and now run the executable, it should run without a problem.
However I am not too sure if this will cause unreliable results or any other sort of problems later. I guess its best to check the code to find out and remedy the error causing this.
Could the following be of any use ?
http://valgrind.org/
See this page to understand how valgrind can help you.
Friday, July 25, 2008
#define main
I have two files and the contents are as follows :
lines
#ifndef main
#define main
If I change it to
#ifndef Main
#define Main
or
#ifndef MAIN
#define MAIN
etc.
the program compiles.
Turns out that the line
#define main
actually defines the macro ``main" with an empty value. When the preprocessor works on the code it replaces all instances of the word main with an empty string resulting in the compile time error as posted above.
To find out the error just see the effect of preprocessor on the code before and after changing the macro name from main to Main or MAIN or whatever.
The effect of the preprocessor can be seen with the following command :
g++ -E main.cpp
Mind you that the above command will produce lots and lots of code ( in my case about 30000 lines of code). So this is what you can do
First with the erroneous header file ::
g++ -E main.cpp > outputA
and then with the fixed header file ::
g++ -E main.cpp > outputB
now compare the files outputA and outputB with the diff utility.
diff outputA outputB
You will find that the preprocessor working on the erroneous code produces
int (void)
while the preprocessor working on the correct code produces
int main(void)
Thanks to the gurus at gnu.g++.help I could understand the error I was making !
The thread can be found here.
p.s. I work on GNU/Linux with the gcc compiler.
file :: main.h
-------------------------------------
#ifndef main
#define main
#endif
--------------------------------------
and
file :: main.cpp
-------------------------------------
#include "main.h"
int main(void)
{
return 0 ;
}
------------------------------------
This program does not compile and the error message that I get is ::
expected unqualified-id before ‘void’
expected `)' before ‘void’
lines
#ifndef main
#define main
If I change it to
#ifndef Main
#define Main
or
#ifndef MAIN
#define MAIN
etc.
the program compiles.
Turns out that the line
#define main
actually defines the macro ``main" with an empty value. When the preprocessor works on the code it replaces all instances of the word main with an empty string resulting in the compile time error as posted above.
To find out the error just see the effect of preprocessor on the code before and after changing the macro name from main to Main or MAIN or whatever.
The effect of the preprocessor can be seen with the following command :
g++ -E main.cpp
Mind you that the above command will produce lots and lots of code ( in my case about 30000 lines of code). So this is what you can do
First with the erroneous header file ::
g++ -E main.cpp > outputA
and then with the fixed header file ::
g++ -E main.cpp > outputB
now compare the files outputA and outputB with the diff utility.
diff outputA outputB
You will find that the preprocessor working on the erroneous code produces
int (void)
while the preprocessor working on the correct code produces
int main(void)
Thanks to the gurus at gnu.g++.help I could understand the error I was making !
The thread can be found here.
p.s. I work on GNU/Linux with the gcc compiler.
Thursday, July 3, 2008
Handling matrices in C++
Most of my programming work in C++ involves numerical computation based work. I have to deal with a lot of 2-dimensional matrices and the approach that I stuck to earlier was to use a pointer to a pointer.
This allows for dynamic allocation of matrices. However I can't pass a pointer to a pointer and use const protection at the same time.
Say I have a function that just takes the 2-dimensional matrix and displays it. Now I want to protect the matrix from being inadvertently changed in the called function. So I want to declare the function as follows:
The above can't be done :(
I am not even aware if a 2-dimensional array can be passed by reference in C++.
So this is what I am trying instead.
Say I have a 2-D matrix A as follows:
then instead of defining this as :
I define it as a single dimension array as follows :
That way one can easily pass the pointer as follows
-----------------------------------------------------------------
If you know a better solution please DO let me know.
double** matrix;
This allows for dynamic allocation of matrices. However I can't pass a pointer to a pointer and use const protection at the same time.
Say I have a function that just takes the 2-dimensional matrix and displays it. Now I want to protect the matrix from being inadvertently changed in the called function. So I want to declare the function as follows:
void function(const double** const matrix); // WRONG
The above can't be done :(
I am not even aware if a 2-dimensional array can be passed by reference in C++.
So this is what I am trying instead.
Say I have a 2-D matrix A as follows:
A = [1, 2,3]
[4,5,6]
[7,8,9]
[4,5,6]
[7,8,9]
then instead of defining this as :
A [3][3] = { {1,2,3}, {4,5,6}, {7,8,9}};
I define it as a single dimension array as follows :
A[9] = { 1,2,3,4,5,6,7,8,9} ;
That way one can easily pass the pointer as follows
void function(const double * const A );
-----------------------------------------------------------------
If you know a better solution please DO let me know.
Tuesday, July 1, 2008
Sunday, June 22, 2008
find the location/path of m-files
use the ``which" command .
i was trying to figure out where the mutools toolbox was in MATLAB 7. couldn't find it. then i remembered the ``which" command
>> which pck
wallah !!!!!
i want a circle not ellipse
theta = 0:0.1:2*pi ;
x = cos(theta);
y = sin(theta);
plot(x,y);
shg
this should show u a circle instead it shows u an ellipse.. not that the program is wrong or something !
just write
axis equal
at the command prompt and all should be ok
more
i have a bad memory and i always check out the help associated with the function or script that i am using. most of the times the help output is voluminous and scrolls off the screen.
Try this out
>> help mincx
i don't like that and don't want to type
>> more on
before every invocation of help
so this is what i did
open help file and right and the end of the help messages but before the beginning of all the commands just add this line
more on;
this should do the job since all my scripts have by default more off and the beginning.
another cool thing i found out was to check if more has been set in the command window
get(0,'more')
this is actually a cool find since this lets me find awful lot of information about the main command window environment
Try this out
>> help mincx
i don't like that and don't want to type
>> more on
before every invocation of help
so this is what i did
open help file and right and the end of the help messages but before the beginning of all the commands just add this line
more on;
this should do the job since all my scripts have by default more off and the beginning.
another cool thing i found out was to check if more has been set in the command window
get(0,'more')
this is actually a cool find since this lets me find awful lot of information about the main command window environment
Linear Optimal Control Systems by H. Kwakernaak and R. Sivan
In order to preserve the Control Systems literature, the Control Systems Society will make available without cost out of print books that had significant impact on the field.
Now isn't that just great !!! So why wait head over to this page and enjoy the book :D
transient response of non-linear systems
transient response of Finite Dimensional Linear Time Invariant (FDLTI) systems is determined by locations of the system poles, however for nonlinear systems there IS no concept of "poles of the system". in that case what really governs the transient response. what computable property/properties of a nonlinear system will be equivalent to "poles of a FDLTI system" ?
pid
i should feel ashamed in writing about this but i guess one has to confess his or her sins at one time or another.
the transfer function of a pid controller is NOT strictly proper
U(s) kd*s^2 + kp*s + ki
----- = -------------------- (1)
E(s) s
doesn't it create any problems ? all undergraduate control texts say that transfer functions are(should be?) strictly proper. there is something amiss here.
my guess is that since its physically impossible to construct a pure differentiator
( kd*s term ) its therefore impossible to physically construct a PID controller
the transfer function of a pid controller is NOT strictly proper
U(s) kd*s^2 + kp*s + ki
----- = -------------------- (1)
E(s) s
doesn't it create any problems ? all undergraduate control texts say that transfer functions are(should be?) strictly proper. there is something amiss here.
my guess is that since its physically impossible to construct a pure differentiator
( kd*s term ) its therefore impossible to physically construct a PID controller
degree of non-linearity
with reference to non-linear systems: is it fair rather meaningful to ask about the ``degree of non-linearity" of a system. all linear systems are linear, nothing big about it; however since the domain of nonlinear systems is vast, can the phrase/clause ``degree of non-linearity" be given some meaning?
Laplace Transform
Why is the Laplace variable a complex number? The meaning of complex frequency is made clear in the book by Valkenburg.
What does the Laplace transform do to the integro-differential equations that makes an algebraic manipulation possible?
What does the Laplace transform do to the integro-differential equations that makes an algebraic manipulation possible?
step response
The system G(s) = (s+1)/( s*(s+3)*(s*s+4*s+8)) with poles at
0
-3.0000
-2.0000 + 2.0000i
-2.0000 - 2.0000i
and a zero at -1 has all stable poles, i.e. in the left hand of the s-plane . However the step response of the system is unstable !!!!
This is most probably due to the pole at the origin. The system then behaves as a double integrator. The impulse response of the plant does not decay to zero ! The plant is decidedly unstable.
This is food for thought , since before this I thought that the stability of the system could be determined my the location of poles alone. It now seems that its also important that whether the poles in question are open loop or closed loop !
0
-3.0000
-2.0000 + 2.0000i
-2.0000 - 2.0000i
and a zero at -1 has all stable poles, i.e. in the left hand of the s-plane . However the step response of the system is unstable !!!!
This is most probably due to the pole at the origin. The system then behaves as a double integrator. The impulse response of the plant does not decay to zero ! The plant is decidedly unstable.
This is food for thought , since before this I thought that the stability of the system could be determined my the location of poles alone. It now seems that its also important that whether the poles in question are open loop or closed loop !
pole zero cancellation
say a controllable system uses state feedback to cancel a zero in the lhs of s-plane. the system becomes unobservable. but does this cause ne probs. i think not. since at the start the system was controllable and observable(my assumption) what harm does it cause if now the system becomes unobservable. u need an observer only if u can't measure one or more state; so if u start with an observable and controllable system there is no problem in setting up a state feedback controller using an observer.
Subscribe to:
Posts (Atom)