-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCouve.java
48 lines (41 loc) · 1.59 KB
/
Couve.java
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
import java.util.Arrays;
public class Couve {
public static void scaledIncrement(double[] a, double s, double[] b) {
for (int i = 0; i < a.length; i++)
a[i] = a[i] + s * b[i];
}
public static void main(String[] args) {
double[] a = {0, 3, 5, -1, 7, 0, 3, 2, 1, 5, 6, 7, 0, 1, 2, 3, 5, -1, 7, 0, 3, 2, 1, 5, 6, 7, 0, 1, 2, 1};
double[] b = {3, 0, 5, 0.95, 7, 5, 3, 2, 1, 5, 6, 7, 0, 1, 2, 3, 0, 5, 0.95, 7, 5, 3, 2, 1, 5, 6, 7, 0, 1, 2};
double c = 3;
System.out.println(Arrays.toString(a));
scaledIncrement(a, c, b);
System.out.println("novo a:" + Arrays.toString(a));
System.out.println(dotProduct(a, b));
//System.out.println(Arrays.toString(scale(c, a)));
Double[] arr = {4.2, 2.3333, 1., 9.};
printArray(arr);
}
public static double dotProduct(double[] arr1, double[] arr2) {
double produtoEscalar = 0;
for (int i = 0; i < arr1.length; i++)
produtoEscalar += arr1[i] * arr2[i];
return produtoEscalar;
}
/*public static double[] scale(double s, double[] arr) {
double[] ret = null;
ret = new double[arr.length];
for (int i = 0; i < arr.length; i++)
ret[i] = s * arr[i];
return ret;
}*/
public static void scale (double s, double[] arr) {
for (int i = 0; i < arr.length; i++) {
arr[i] = s * arr[i];
}
}
private static void printArray(Object[] arr) {
for (int i = 0; i < arr.length; i++)
System.out.println("posicao" + i + ": " + arr[i]);
}
}