Skip to content
Snippets Groups Projects
Commit 74ea09e9 authored by iliya's avatar iliya
Browse files

vectors

parent 32cf5495
No related branches found
No related tags found
No related merge requests found
import com.sun.tools.javac.util.List;
public class Vector {
public static double[] add(double[] lhs, double[] rhs) {
double res[] = new double[3];
for (int i = 0; i < res.length; i++) {
res[i] = lhs[i] + rhs[i];
}
return res;
}
public static double[] scalar_mul(double[] vec, int scalar) {
double res[] = new double[3];
for (int i = 0; i < vec.length; i++) {
res[i] = vec[i] * scalar;
}
return res;
}
public static double[] sub(double[] lhs, double[] rhs) {
double invert_lhs[] = scalar_mul(lhs, -1);
double res[] = add(rhs, invert_lhs);
return res;
}
public static int len(double[] vec) {
return vec.length;
}
public static double norm(double[] vec) {
double res;
for (int i = 0; i < vec.length; i++) {
sum += vec[i];
}
return Math.sqrt(res);
}
public static double[] sum(List<double[]> vec_list) {
double[] res;
for (int i = 0; i < vec_list.length; i++) {
res += add(res, vec_list[i]);
}
return res;
}
public static double[] norms(List<double[]> vec_list) {
double[] res;
for (int i = 0; i < vec_list.length; i++) {
res += norm(vec_list[i]);
}
return res;
}
public static double[] concat(double[] lhs, double[] rhs) {
int len = lhs.length + rhs.length;
double res[] = new double[len];
for (int i = 0; i < lhs.length; i++) {
res[i] = lhs[i];
}
for (int i = lhs.length; i < res.length; i++) {
res[i] = rhs[i - lhs.length];
}
return res;
}
public static double[] sliceFrom(double vec[], int stop_idx) {
double[] res;
if (stop_idx < 0) {
throw new Exception("Specified index: " + stop_idx + " is smaller than zero");
}
try {
for (int i = 0; i < stop_idx; i++) {
res[i] = vec[i];
}
} catch (IndexOutOfBoundsException e) {
System.err.println("L'indice spécifié " + i + " dépasse la capacité du vecteur");
}
}
public static double[] slice(double[] vec, int start_idx, int stop_idx) {
if (start_idx < 0 || stop_idx < 0) {
throw new Exception("Index or indices out of bounds");
}
double[] up_to_stop = sliceFrom(vec, stop_idx);
}
public static void main(String[] args) {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment