class
GFG{
static
double
magnitude(
double
arr[],
int
N)
{
double
magnitude =
0
;
for
(
int
i =
0
; i < N; i++)
magnitude += arr[i] * arr[i];
return
Math.sqrt(magnitude);
}
static
double
dotProduct(
double
[] arr,
double
[] brr,
int
N)
{
double
product =
0
;
for
(
int
i =
0
; i < N; i++)
product = product + arr[i] * brr[i];
return
product;
}
static
void
angleBetweenVectors(
double
[] arr,
double
[] brr,
int
N)
{
double
dotProductOfVectors = dotProduct(arr, brr, N);
double
magnitudeOfA = magnitude(arr, N);
double
magnitudeOfB = magnitude(brr, N);
double
angle = dotProductOfVectors /
(magnitudeOfA * magnitudeOfB);
System.out.println(angle);
}
public
static
void
main(String[] args)
{
double
[] arr = { -
0.5
, -
2
,
1
};
double
[] brr = { -
1
, -
1
,
0.3
};
int
N = arr.length;
angleBetweenVectors(arr, brr, N);
}
}