• Pada Algoritma pencarian banyak yang bisa kita temukan atau gunakan. Ada Merge Sort, Quick Sort, Bubble Sort, dan...
  • Pada dasarnya algoritma searching banyak kita jumpai. Apalagi hanya untuk mencari nilai minimum dan nilai maximum...
  • Kalian pasti sudah tahu apa itu Deret Fibonacci, ya benar. (Padahal gak jawab). Tetapi pada pembahasan kali ini kita akan membuar program...
  • Metoda Pencarian Biner ( Binary Search) hanya bisa diterapkan jika data array sudah terurut. Pengurutan Array bisa menggunakan jenis sorting ...
  • Salah satu contoh tipe algoritma brute force lainnya adalah linear search (pencarian berurutan), Dikatakan demikian karena algoritma ini menggunakan ...

Friday, May 13, 2011

Vektor : Program C + + Vector Addition and Multiplication Vector (Program C++ Penjumlahan Vektor dan Perkalian Vektor)

SKALAR AND VEKTOR

Scalar is a quantity sufficient magnitude is expressed alone (not dependent on the way). For example: mass, time, energy and so on.
The vector is a quantity that depends on the direction. For example: speed, force, momentum, etc.

In Cartesian coordinates :
       Vector direction / unit vector is a vector of magnitude 1 and in accordance with a defined direction. For example in Cartesian coordinates: i, j, k, respectively - each state vector in the direction parallel to the x axis, y axis and the axis z.
        So that the vector a can be written :

                                a = ax  i + ay  j

          and the large vector a is :
         
                                a = sqrt( ax +  ay 2 )
Addition operation :
A + B = ?
        + Sign in the summation vector has extended meanings.
         So A + B has a mean vector A may be extended by the vector B.

Vector multiplication by scalar :
Examples of a vector multiplication by a scalar in physics: F = ma, p = mv, etc.
where m: scalar and a, v: vector.
If for example A and B are vectors and k is a scalar then,

                    B = k A

Large vector B is k times while the direction of the vector A vector B is equal to the direction of vector A when k positive and the opposite if k is negative. Example: F = QE, q is the electric charge can be charged positive or negative so that the direction of F depends on the charge sign.

Based on the case, here's created a program to compute the vector addition and multiplication by a scalar vector. To sum ​​as follows :

void vektor::penjumlahan_vektor(const vektor& a, const vektor& b){
     if (a.banyak > b.banyak) banyak = a.banyak;
     else banyak = b.banyak;
     for(int i=0;i<banyak;i++){
             elemen[i] = a.elemen[i] + b.elemen[i];
             }
     }
    
For vector multiplication with skalar be made ​​like this :

void vektor::perkalian_vektor(float k, const vektor& d){
     banyak = d.banyak;
     for(int i=0;i<banyak;i++){
             elemen[i]=k * d.elemen[i];
             }
     }

Complete program can be downloaded here

Jadilah yang pertama mengomentari

Post a Comment

Tutorial Algorithm and Programming ©Template Blogger Green by Dicas Blogger.

To Up