-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion1.c
More file actions
56 lines (41 loc) · 1.18 KB
/
Question1.c
File metadata and controls
56 lines (41 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "Questions.h"
void add_vectors(double vector1[],double vector2[],double vector3[],int size)
{
/*vector3 should store the sum of vector1 and vector2.
You may assume that all three arrays have the size equal to the input parameter "size"
*/
//write your code below
int i;
for (i = 0; i < size; i++)
{
vector3[i] = vector1[i] + vector2[i];
}
}
double scalar_prod(double vector1[],double vector2[],int size)
{
// this is the variable holding the scalar product of the two vectors
double prod=0;
//write your code below to calculate the prod value
int i;
for (i = 0; i < size; i++)
{
prod += vector1[i] * vector2[i];
}
// return the result
return prod;
}
//The 𝓁2 norm is the vector magnitude
//vector magnitude formula: 𝓁2 = sqrt(x² + y² + z²)
double norm2(double vector1[], int size)
{
//this is the variable holding the L2 norm of the passed vector
double L2;
//write your code here
// you should call function scalar_prod().
L2 = sqrt(scalar_prod(vector1,vector1,size));
//finally, return the L2 norm
return L2;
}