Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
otsall
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d2cc44f0
authored
6 years ago
by
otsall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lab5
parent
0fe10c4a
master
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
Lab5/vectorangles.c
Lab5/vectorangles.c
0 → 100644
View file @
d2cc44f0
#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
)));
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment