Commit d2cc44f0 by otsall

lab5

parent 0fe10c4a
Showing with 38 additions and 0 deletions
#include<stdio.h>
#include<math.h>
double cosine(int i, int k);
double angle;//the angle
int i,//matrix row, vector nr
j,//matrix column, vector coordinate
k,//target vector nr
matrix[4][3] = {
{ 1, 4, 6},
{ 2, -3, 1},
{ 3, 5, 0},
{ 3, 1, -3}
};
int main(){
for(i = 0; i < 3; i++){
for(k = i + 1; k < 4; k++){
angle = acos(cosine( i, k));
printf("%lf\n", angle);
}
}
return 0;
}
double cosine(int i, int k){
double dotProd = 0,
length_i = 0,
length_k = 0;
for(j = 0; j < 3; j++){
dotProd = dotProd + matrix[i][j]*matrix[k][j];
length_i = length_i + pow(matrix[i][j], 2);
length_k = length_k + pow(matrix[k][j], 2);
}
return(dotProd / (sqrt(length_i) * sqrt(length_k)));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment