Swordrock's Blog

Just another WordPress.com site

Introduction to Linux with Ubuntu


Hey its been a long time that i can not write but now i will . I begin to use Linux OS for a school project and now i am learning how to do things on Ubuntu 10.04 . Everything is so much clear and faster than windows on linux , trust me .

A code developer must do all its work on linux because there is so much useful libraries , scripts and other good stuffs here for you to develop good things with them.Someone says its so hard to get used to it , dont believe them and begin as quickly as possible.

 

To begin to use Ubuntu , first i downloaded it from internet , as you guess its all free  .You can use these links for installation guide and download  :

http://www.ubuntu.com/download/ubuntu/download

https://help.ubuntu.com/community/Installation

http://seogadget.co.uk/the-ubuntu-installation-guide/

 

Ubuntu comes with a default Desktop enviroment called GNOME , and it seems so much like a windows , you can listen to music , surf on web , use office programs just like you did it on microsoft windows . So no problem…

Ubuntu gives you chance to work on different Desktop enviroments , they differ on Ram usage and other capabilities. As a developer my teacher said we need a superlight Desktop enviroment , then i choose XFCE . Its also so easy to download and begin to use . You can also get info about Xubuntu from there :

http://www.psychocats.net/ubuntu/xubuntu

http://www.xubuntu.org/get

 

Then Ubuntu = Command window , you can do a lot using command window , and you will if you go on using this OS . I will share some important command for us beginners on it , and there is also so much useful link for this subject  , please read efficiently the Linux Command part , they are so good  :

http://linuxcommand.org/

 

Some important commands … You can add a new user by typing ;

>>useradd

You can change password by typing passwd  command .

Using cd command will change current directory and pwd will print the current directory you are still working in .

Then some file operations , you can add a new directory using mkdir command ,it is removed using rmdir .

You can move files using mv command and also can erase them using rm command .

A very important thing  : Dont act as a superuser !! Its so much important , on linux as a default there is a superuser , who is unlimited and can do and change everything , and other users who are called normal . As a superuser , you can erase everything or change system configurations which will result in a fatal way .Dont do it . To act as a normal user , use sudo command , like :

>> sudo apt get install

command will install what you will type as argument on linux as a normal user .

 

Now i will come some development things . Using linux for development is different from how we do on windows . The steps for printing Hello world in C language like that :

1) Open a file in your current directory and write these codes in it :

# include <stdio.h> // standart in and standart out steams library

 

int main () {

printf (“Hello world”);

return 0;

}

2 ) Save this file as “hello.c”  then close it .

3)Open your command window , first we must compile to use it . To compile , type this command on window :

gcc -o hello hello.c

 

GCC is C compiler on linux and know what to do ,reprocessing , compiling , linking …

-o command means an output named hello will be written after compilation completed .

 

4) Now we are ready to run it . You run programs on linux by these commands :

 

./hello

 

This will print a hello world to our page.

 

For a last thing , i will talk about OpenCV libraries . I will use OpenCV libraries on linux for our school projects and as you guess first i have to install it on my Ubuntu . OpenCV is a image processing , gui development and computer vision free library of Intel.So much thanks to Intel for publishing it free .

 

Like a lot of user , i use SAMONTAB s method on installing and trying libraries , the adress is here :

http://www.samontab.com/web/2010/04/installing-opencv-2-1-in-ubuntu/

 

It works fine , then try face detection example to make sure if you do all steps good .

 

Thanks for reading , i will go on sharing about linux and OpenCV and C development using linux . I hope 🙂 Bye !

 

 

 

 

Temmuz 9, 2011 Posted by | C/C++ programming | , , , , | Yorum bırakın

C++ matrix operations


Hi!

 

Today i will share some arithmetic operations with C++ like addition , multiplication , transpose and inverse

 

1)ADDITION

this program takes a 3×3 matrix as an input and gives the total value (2xN) .

 

—————————————————

 

#include <iostream>
using namespace std ;

int main ()
{
int i,j,b[3][3]={0},n[3][3]={0}; // definition of variables

cout<<“enter the values for 3×3 matrix : “<<endl;
// cout<<“entering to for …”<<endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++) {

cout<<“(“<<i<<“,”<<j<<“)=”;
cin>>n[i][j];
cout<<endl;

b[i][j]=2*n[i][j];

}
}

////////////////////////////////////////////////////////////////////////////////////
//addition printing
cout<<“Sum : “<<endl;
for(i=0;i<3;i++){
cout<<endl;
for(j=0;j<3;j++) {
if (i==2 && j==2) cout<<‘\t’;

cout<<“(“<<i<<“,”<<j<<“)=”<<b[i][j]<<‘\t'<<‘\t’;

}
}

//end of addition printing

////////////////////////////////////////////////////////////////////////////////////
cout<<endl;

system (“pause”);
}

 

—————————————————

 

2)MULTIPLICATION

In this program i take values of a 3×3 matirx and take square of it

—————————————————

 

#include <iostream>
using namespace std ;

int main ()
{

int i,j,c[3][3]={0},a[3][3]={0},n[3][3]={0};   // defition of variables

cout<<“enter values for 3×3 matrix : “<<endl;
// cout<<“entering to for …”<<endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++) {

cout<<“(“<<i<<“,”<<j<<“)=”;
cin>>n[i][j];
cout<<endl;

c[i][j]=n[i][j]*n[i][j];
}

}

////////////////////////////////////////////////////////////////////////////////////
//multiplication display

cout<<“carpim : “<<endl;
for(i=0;i<3;i++){
cout<<endl; cout<<‘\t’;
for(j=0;j<3;j++) {
if(i==2 && j==2) cout<<‘\t’;
cout<<“(“<<i<<“,”<<j<<“)=”<<c[i][j]<<‘\t’;

}
}

////////////////////////////////////////////////////////////////////////////////////

cout<<endl;
system (“pause”);
}

 

—————————————————

 

 

3)TRANSPOSE

In this program , i take values of a 3×3 matrix and display the transpose of it ,

(if you dont know about transpoze matrix :http://en.wikipedia.org/wiki/Transpose )

 

—————————————————

 

#include <iostream>
using namespace std ;

int main ()
{

int i,j,a[3][3]={0},n[3][3]={0};

cout<<“enter values for 3×3 matrix : “<<endl;
// cout<<“entering to for …”<<endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++) {

cout<<“(“<<i<<“,”<<j<<“)=”;
cin>>n[i][j];
cout<<endl;
a[j][i]=n[i][j]; // calculating the transpose

}

}

 

////////////////////////////////////////////////////////////////////////////////////
//transpose printing
cout<<“tranpose : “<<endl;
for(i=0;i<3;i++){
cout<<endl;
for(j=0;j<3;j++) {

cout<<“(“<<i<<“,”<<j<<“)=”<<a[i][j]<<‘\t’;

}
}

////////////////////////////////////////////////////////////////////////////////////

system (“pause”);
}

 

—————————————————

 

4)INVERSE

 

In this program  , i calculate the inverse of a 3×3 matrix , i use determinant method , you can also find inverse programs done by gauss-jordan method

—————————————————

 

#include <iostream>
using namespace std ;

int main ()
{

cout<<“enter values for 3×3 atrix : “<<endl;
// cout<<“entering to for …”<<endl;

int z,j,i,n[3][3];
double a[3][3];

for(i=0;i<3;i++){
cout<<endl;
for(j=0;j<3;j++) {

cout<<“(“<<i<<“,”<<j<<“)=”;
cin>>n[i][j];
cout<<endl;

}

}

// adjoint matrix calculation

a[0][0]=n[1][1]*n[2][2]-n[1][2]*n[2][1];
a[0][1]=n[1][2]*n[2][0]-n[1][0]*n[2][2];
a[0][2]=n[1][0]*n[2][1]-n[1][1]*n[2][0];
a[1][0]=n[0][2]*n[2][1]-n[0][1]*n[2][2];
a[1][1]=n[0][0]*n[2][2]-n[0][2]*n[2][0];
a[1][2]=n[0][1]*n[2][0]-n[0][0]*n[2][1];
a[2][0]=n[0][1]*n[1][2]-n[0][2]*n[1][1];
a[2][1]=n[0][2]*n[1][0]-n[0][0]*n[1][2];
a[2][2]=n[0][0]*n[1][1]-n[0][1]*n[1][0];

z=n[0][0]*a[0][0] + n[0][1]*a[0][1] + n[0][2]*a[0][2];

////////////////////////////////////////////////////////////////////////////////////

// inverse  printing

cout<<“determinant : “<<z<<endl;
cout<<“inverse of matrix :  : “<<endl;
for(i=0;i<3;i++){
cout<<endl; cout<<‘\t’;
for(j=0;j<3;j++) {
if(i==2 && j==2) cout<<‘\t’;
cout<<“(“<<i<<“,”<<j<<“)=”<<a[j][i]/z<<‘\t’;

}
}

cout<<endl;
////////////////////////////////////////////////////////////////////////////////////

system (“pause”);

}

 

—————————————————

 

 

We did some arithmetic calculations with C++ today , see you !

 

 

Aralık 26, 2010 Posted by | C/C++ programming | , , , , , | Yorum bırakın