To compile gnuplot in snow leopard use the following command:
./configure --with-readline=bsd --x-include=/usr/include/X11 --x-libraries=/usr/X11/lib
and then use make and sudo make install.
Sunday, September 6, 2009
Wednesday, November 12, 2008
Ruby
I apologize for not posting here for almost half a year now. I have started to learn ruby and I'm impressed with I have seen so far. I read the book/tutorial in http://pine.fm/LearnToProgram/ it didn't take me much time since it's geared to someone learning how to program for the first time, but you get much of the syntax of the language just by reading the tutorial.
The most interesting part of the tutorial is chapter 10. Procs is nothing new, and is not unique to ruby, from a C perspective it gives the programmer much more flexibility.
I can think of many cases where passing Procs to Methods and return Procs from Methods would be useful, i.e. make a method that will return the n_th Laguerre polynomial using the Rodrigues formula. Notice we are not evaluating the n_th Laguerre polynomial at x. We are evaluating a function that will calculate the n_th polynomial at any x.
Cheers.
The most interesting part of the tutorial is chapter 10. Procs is nothing new, and is not unique to ruby, from a C perspective it gives the programmer much more flexibility.
I can think of many cases where passing Procs to Methods and return Procs from Methods would be useful, i.e. make a method that will return the n_th Laguerre polynomial using the Rodrigues formula. Notice we are not evaluating the n_th Laguerre polynomial at x. We are evaluating a function that will calculate the n_th polynomial at any x.
Cheers.
Wednesday, July 9, 2008
Skribit
I have added a new widget, it's called skribit and it will allow to make suggestions for my blog. I have not worked a lot on the blog lately but I'm planning to make some changes in the future.
Best Regards
Chuy
Best Regards
Chuy
Thursday, June 12, 2008
NExT step machine
Jacob, Sahil and Me won a NExT machine (no one else wanted it) from the experts. Nice! Now we need some power cables to get it to work. More to come stay tuned.
Tuesday, May 20, 2008
Wednesday, April 23, 2008
Good Video
Thursday, April 17, 2008
Thursday, February 14, 2008
2008 A New Year
2008 is here. And it has been here for a while now. I'm just getting started on a new job so I haven't published anything new for a while. With the job change there is also a small change (not a big one in this case) on my research area. I will start doing some Density Functional Calculations (DFT) so I might be talking a little bit about it on here from time to time. In the mean while I'm using the MIT open courseware to start learning the techniques used to do this kind of calculations. If you are interested you can take a look at Atomistic Computer Modeling of Materials.
Best Regards
Chuy
Best Regards
Chuy
Monday, December 17, 2007
Google Chart API : part II
I solve my mistake, if you want to use charts into blogger just don't break the src=".." lines into pieces like I did in the example in the last post. The whole src have to be in one line.
Google Chart API

This chart was made using Google Chart API.
After Playing for a while trying to generate the previous plot I couldn't use google API properly. I had to generate the plot on my personal website save it to disk and post it. This API is a great way to make real-time charts, but for some reason it doesn't work within blogger it must disabled for security issues or something.
There is a couple of things I don't like about the API, and some serious limitations so I will stick to gnuplot. but it's nice to have different options with different capabilities.
The biggest problem I find with this API is that you must format your data to make it compatible with the API. Lets say you are running a simulation, and your output data ranges from 1 Tesla to 7.24 Teslas dependent on Temperature, you will need to map the data from 1 to 100, label the chart appropriately so it reads 7.24 on the highest data point and make sure your Temperature interval is uniform. It's not a difficult transformation but it's annoying.
On the other hand, if you are running your simulation on a server, you can easily modify your program so it will write a preview output. Lets say 1 of every 100 points calculated goes to this preview output. And make a web page you can access from any computer with firefox. The web page will then plot in real time what this preview output file looks like. It's also possible to make a web page that will take track of several simulations running on different servers (computers).
The code used to generate the chart is:
<img src="
http://chart.apis.google.com/chart?
cht=lc
&chco=ff0000,00ff00,0000ff
&chs=200x125&chd=t:0,0,0.3,0.7,1.2|0,0.3,1.4,3.1,5.3|0,0.8,3.9,8.7,15.2
&chxt=x,y
&chxl=0:|0|1.0|2.0|1:||20||60||100"
>
Tuesday, December 11, 2007
Reasons not to publish.
I recently run into this short story:
Reasons not to publish. by Gregory Benford.
Reasons not to publish. by Gregory Benford.
Friday, November 16, 2007
Multivalued hell
Hello All.
I have been unable to post stuff thanks to my new friends called multivalued funtions and brach which have been keeping from doing any progress on my research. So next time you use any of these multivalued function (i.e. the arcsin(x)) stop to think about it for a second, I will.
I'm working on the second part of the linked list post, that should come out soon. Also this month on the cise publication the article "On the evaluation of Finite Hilbert Transforms" proposes the double exponential method as a good numeric method to find Hilbert Transforms. I talked about Hilbert Transforms before, and I use them in my research so I will implement the method and publish the code on here.
One more thing. This is just a mathematical curiosity. I was trying to calculate the derivate of x^x, as it turns out you can take the natural log on both sides of the equation before taking the derivative. I get ln(x^x) = ln(x*x*x*...) = x*ln(x) but this bugs me since x doesn't have to be an integer. Any ideas?
I have been unable to post stuff thanks to my new friends called multivalued funtions and brach which have been keeping from doing any progress on my research. So next time you use any of these multivalued function (i.e. the arcsin(x)) stop to think about it for a second, I will.
I'm working on the second part of the linked list post, that should come out soon. Also this month on the cise publication the article "On the evaluation of Finite Hilbert Transforms" proposes the double exponential method as a good numeric method to find Hilbert Transforms. I talked about Hilbert Transforms before, and I use them in my research so I will implement the method and publish the code on here.
One more thing. This is just a mathematical curiosity. I was trying to calculate the derivate of x^x, as it turns out you can take the natural log on both sides of the equation before taking the derivative. I get ln(x^x) = ln(x*x*x*...) = x*ln(x) but this bugs me since x doesn't have to be an integer. Any ideas?
Friday, October 26, 2007
Leopard. Comming out tomorrow.
Some of you might know this. Leopard is coming out tomorrow at 6pm.
I will go tomorrow to an apple store and play a little bit with it, unfortunately I'm not buying it until a few months from now.
I really want to see spaces working and the new finder. Quick view sounds interesting and I wonder if you can make your own quick views. i.e. if I'm going to store the output of my program on an archive .dat then I can just open it with quick view and see the data as a plot. I guess this would be rather difficult to achieve, but it would be nice anyway.
I will talk about Leopard a little bit more next week. Take care.
I will go tomorrow to an apple store and play a little bit with it, unfortunately I'm not buying it until a few months from now.
I really want to see spaces working and the new finder. Quick view sounds interesting and I wonder if you can make your own quick views. i.e. if I'm going to store the output of my program on an archive .dat then I can just open it with quick view and see the data as a plot. I guess this would be rather difficult to achieve, but it would be nice anyway.
I will talk about Leopard a little bit more next week. Take care.
Monday, October 8, 2007
Compiling for PPC from an Intel Mac.
Most mac users, might be familiar with universal applications. An universal application is an application such that it will run natively on either an Intel mac or a Power PC (PPC) mac. I was thinking about parallelization and I realized that if I wanted to do it between my two macs (a mac mini PPC and a Mac Book Pro Intel core duo) I have to do universal applications.
If you use Xcode you might know that making universal binaries (programs) is easy just by modifying the project properties. But for the most part I don't use Xcode I mainly use the terminal to compile. In this case the solution is quite easy too.
I made a Hello World application in C. Usually I will compile using
the result is an executable file named a.out (17 Kb in size) that will run on my Mac Book Pro, if I try to run this code in my mac mini an error will occur. Using the flag -arch we can specify a different architecture, i.e.
the result is once again an executable named a.out (20 Kb in size), this code will run in the mac mini natively. It will also run on the Intel mac but it will not be native reducing the performance of the code.
Finally if we want to run this code on natively on both PPC and Intel we would use the following command
the result is an executable a.out (40 Kb in size), that contains both a PPC native and a Intel native binary.
This flag option is exclusive to mac platform, so it won't work on Linux machines. I try running each one of the 3 executables produced on a Linux machines, as expected no one worked.
I have been having trouble using the GSL (Gnu Scientific Library) and generating universal binaries, my best guess is that I have to compile the libraries again for PPC but I don't have the time, energy nor patience to do it.
If you use Xcode you might know that making universal binaries (programs) is easy just by modifying the project properties. But for the most part I don't use Xcode I mainly use the terminal to compile. In this case the solution is quite easy too.
I made a Hello World application in C. Usually I will compile using
g++ Hello.cpp
the result is an executable file named a.out (17 Kb in size) that will run on my Mac Book Pro, if I try to run this code in my mac mini an error will occur. Using the flag -arch we can specify a different architecture, i.e.
g++ Hello.cpp -flag ppc
the result is once again an executable named a.out (20 Kb in size), this code will run in the mac mini natively. It will also run on the Intel mac but it will not be native reducing the performance of the code.
Finally if we want to run this code on natively on both PPC and Intel we would use the following command
g++ Hello.cpp -flag i386 -flag ppc
the result is an executable a.out (40 Kb in size), that contains both a PPC native and a Intel native binary.
This flag option is exclusive to mac platform, so it won't work on Linux machines. I try running each one of the 3 executables produced on a Linux machines, as expected no one worked.
I have been having trouble using the GSL (Gnu Scientific Library) and generating universal binaries, my best guess is that I have to compile the libraries again for PPC but I don't have the time, energy nor patience to do it.
Friday, October 5, 2007
It's all about linux.
Thursday, October 4, 2007
Scientific programing an database structures. The Linked List part 1/3
In my experience many times database structures are not necessary while doing basic scientific simulations. Most of the time we are dealing with fixed length vectors or matrices. Some of you might disagree with me and might point out that appropriate data management is always necessary. In any case is unfortunate that when the occasion arises this structures are often neglected.
I will try to code from scratch in Objective-C some of the basic database structures and talk a little bit about them. This week I will start with a linked list.
If you are familiar with arrays you are familiar with liked lists. A linked list is a list of nodes, each node stores an object (may be an integer, a double, or any complicated class like a molecule) and a link or pointer to the next object in the list. You might think of it like a shoe box storing something (some data). Each shoe box have a string connected to another shoe box, if you want to locate something you just have to look for it on each box one at the time (following the string so you won't look in the same box twice). I will talk more about linked lists in a next post, but now lets code the nodes.
We will implement a linked list in Objective C.
First make the interface file and name it "LinkedListNode.h"
Second make the implementation file "LinkedListNode.m"
Finally make sure they work as expected, make the file "linkedListNode.m"
Make sure everything is in the same folder and compile typing the following command in terminal.
An executable named a.out will be created, you can execute it typing in the terminal.
The output will look like this. Enjoy!
Note: I'm still learning ObjC and I'm not familiar yet with memory leaks, I might have to modify this code just as to make sure I don't have them. If you notice any memory leak in this code, please let me know.
I will try to code from scratch in Objective-C some of the basic database structures and talk a little bit about them. This week I will start with a linked list.
If you are familiar with arrays you are familiar with liked lists. A linked list is a list of nodes, each node stores an object (may be an integer, a double, or any complicated class like a molecule) and a link or pointer to the next object in the list. You might think of it like a shoe box storing something (some data). Each shoe box have a string connected to another shoe box, if you want to locate something you just have to look for it on each box one at the time (following the string so you won't look in the same box twice). I will talk more about linked lists in a next post, but now lets code the nodes.
We will implement a linked list in Objective C.
First make the interface file and name it "LinkedListNode.h"
//2007 chuyandmac.blogspot.com, LinkedListNode.h
//Interface file for the a node to be
//used in a linked list data structure.
#import
@interface LinkedListNode : NSObject {
double value;
LinkedListNode *next;
}
-(id)initWithValue:(double)v;
-(void)setNextNode:(LinkedListNode *)n;
-(void)setValue:(double)v;
-(double)value;
-(LinkedListNode *)next;
@end
Second make the implementation file "LinkedListNode.m"
//2007 chuyandmac.blogspot.com, LinkedListNode.m
//Implementation file for the a node to
//be used in a linked list data structure.
#import "LinkedListNode.h"
@implementation LinkedListNode
-(id)initWithValue:(double) v{
if(self = [super init]){
[self setValue:v];
[self setNextNode:nil];
}
return self;
}
-(void)setNextNode:(LinkedListNode *)n{
next = n;
return;
}
-(void)setValue:(double)v{
value = v;
}
-(double)value{return value;}
-(LinkedListNode *)next{return next;}
@end
Finally make sure they work as expected, make the file "linkedListNode.m"
//2007 chuyandmac.blogspot.com, linkedListNodeTest.m
//Test LinkedListNode.m and LinkedListNode.h
//To compile use
//gcc -ObjC LinkedListNode.m linkedListNodeTest.m -framework Foundation
#import "./LinkedListNode.h"
int main(){
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Testing LinkedListNode.h");
LinkedListNode *node = [[LinkedListNode alloc] initWithValue:2.0];
LinkedListNode *node2 = [[LinkedListNode alloc] initWithValue:3.0];
[node setNextNode:node2];
NSLog(@"node was initialiazed with value %f.",[node value]);
NSLog(@"the second node is linked an has a value %f."
,[[node next] value]);
[node release];
[node2 release];
[pool release];
}
Make sure everything is in the same folder and compile typing the following command in terminal.
gcc -ObjC LinkedListNode.m linkedListNodeTest.m -framework Foundation
An executable named a.out will be created, you can execute it typing in the terminal.
./a.out
The output will look like this. Enjoy!
2007-10-04 23:30:41.786 a.out[609]
Testing LinkedListNode.h
2007-10-04 23:30:41.786 a.out[609]
node was initialiazed with value 2.000000.
2007-10-04 23:30:41.786 a.out[609]
the second node is linked an has a value 3.000000.
Note: I'm still learning ObjC and I'm not familiar yet with memory leaks, I might have to modify this code just as to make sure I don't have them. If you notice any memory leak in this code, please let me know.
Tutorial: Quick trick to make your code run faster on a core duo processor.
The following tutorial should work with an Intel core duo machine regardless the Operating System. Feel free to share with me any suggestions or comments.
Currently I'm working on a code with the following main() method.
I'm calculating the conductivity (for a given model) with 7 different energies over a range of Temperature. Each calculation is independent of the others. I have to say that each one of this calculations requires a lot of cycles but not a lot of memory. This code is not parallel at all and having a core duo processor limits it.

Here is the CPU activity before and after running such program. Notice that one of the cores tops while running the core, but the other doesn't get that much work to do.
First we need to modify our main method to accept parameters. we will give it 3 parameters in this order initial T, delta T, and number of points to calculate.
Our main() method will look like this now.
To get the same answer as to the other main method we just need to run this method twice with the appropriate parameters. We use the following script to do just that. Just open your favorite text editor and write the following
after saving it (lets say you name it brun) you can use the chmod command on terminal to make it an executable.
running ./brun will produce the same results using more processor resources. In theory this should reduce the computing time by half. In this example it took 12 min to run ./brun vs 20 min it took before splitting the load of work between the two cores.

This tutorial assumes no files are modified during the program execution and the output is printed into screen using the printf command. If not the case some workaround can be found by introducing more program parameters, like input and output files.
I hope this tutorial will be usefull Enjoy.
Currently I'm working on a code with the following main() method.
int main(){
double T = 0;
double T_delta = 0.01;
for(int i = 0; i < 20; i++){
T += T_delta;
printf("%f %f %f %f %f %f %f %.14f\n",
T,conduct(1.0,T),conduct(2.0,T),
conduct(3.0,T),conduct(4.0,T),
conduct(5.0,T),conduct(6.0,T),
conduct(7.0,T));
}
return 0;
}
I'm calculating the conductivity (for a given model) with 7 different energies over a range of Temperature. Each calculation is independent of the others. I have to say that each one of this calculations requires a lot of cycles but not a lot of memory. This code is not parallel at all and having a core duo processor limits it.

Here is the CPU activity before and after running such program. Notice that one of the cores tops while running the core, but the other doesn't get that much work to do.
First we need to modify our main method to accept parameters. we will give it 3 parameters in this order initial T, delta T, and number of points to calculate.
Our main() method will look like this now.
int main(int argc, char * const argv[]){
if(argc != 4){
printf("Wrong number of arguments.
Use initial_T delta number of points\n");
return 0;
}
double T = atof(argv[1]);
double T_delta = atof(argv[2]);
int N = atoi(argv[3]);
for(int i = 0; i < N; i++){
T += T_delta;
printf("%f %f %f %f %f %f %f %.14f\n",
T,conduct(1.0,T),conduct(2.0,T),
conduct(3.0,T),conduct(4.0,T),
conduct(5.0,T),conduct(6.0,T),
conduct(7.0,T));
}
return 0;
}
To get the same answer as to the other main method we just need to run this method twice with the appropriate parameters. We use the following script to do just that. Just open your favorite text editor and write the following
./run 0 .01 10 >> out &
./run .1 .01 10 >> out &
after saving it (lets say you name it brun) you can use the chmod command on terminal to make it an executable.
chmod 555 brun
running ./brun will produce the same results using more processor resources. In theory this should reduce the computing time by half. In this example it took 12 min to run ./brun vs 20 min it took before splitting the load of work between the two cores.

This tutorial assumes no files are modified during the program execution and the output is printed into screen using the printf command. If not the case some workaround can be found by introducing more program parameters, like input and output files.
I hope this tutorial will be usefull Enjoy.
Tuesday, October 2, 2007
Apple Wireless Keyboard
Friday, September 28, 2007
Firefox 3, Moebius and 1 Gig
A couple of mock ups of what Firefox 3 might look like. Personally I like the current appearence better.
Firefox 3.0
A picture of 1GB 20 years ago alongside 1GB today.
1 Gig
Finally, National Geographic Publish the best Scientific Images of the year. I personally liked the last one, I also included the link to the related video.
National Geographic.
Moebius Transformation Video.
Enjoy
Firefox 3.0
A picture of 1GB 20 years ago alongside 1GB today.
1 Gig
Finally, National Geographic Publish the best Scientific Images of the year. I personally liked the last one, I also included the link to the related video.
National Geographic.
Moebius Transformation Video.
Enjoy
Tuesday, September 25, 2007
New side bar
There is a new element at the side bar called Progress. It's aimed to keep track of what I'm doing related to this blog.
Subscribe to:
Posts (Atom)






