I'm trying to finding out the relative error with tbe infinite norm with two vectors for the Jacobi method and I obtain an unexpected solution, 1. But the exact value is 24 / 25. Here's my code:
#include <iostream>
#include <math.h>
using namespace std;
double infinite_norm(double b[]) {
double maximum;
for(int i = 0; i < sizeof(b); i++) b[i] = fabs(b[i]);
maximum = b[0];
for(int i = 1; i < sizeof(b); i++) maximum = fmax(maximum, b[i]);
return maximum;
}
double *subtract_vectors(double x[], double y[]) {
for(int k = 0; k <= sizeof(x); k++) x[k] = x[k] - y[k];
return x;
}
double relative_error(double x[], double y[]) {
return infinite_norm(subtract_vectors(x, y)) / infinite_norm(x);
}
int main() {
static double b[] = {6., 25., -11., 15.};
static double c[] = {1., 1., 1., 1.};
cout<<relative_error(b, c)<<endl;
cout<<24. / 25. <<endl;
return 0;
}
In relative_error function calculates well infinite_norm(subtract_vectors(x, y)) and infinite_norm(x), but not the division.