Vektor : Program C + + Vector Addition and Multiplication Vector (Program C++ Penjumlahan Vektor dan Perkalian Vektor)
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 2 + 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.
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