Your code, corrected and commented (with a bit of "optimizations"):
Code:
#include <iostream>
// It helps (in terms of optimization to declare immutable
// arguments as 'const'. And, since the first array is incomplete,
// I've declared all of them incomplete... They must have 3 elements.
// Again, 'static' here is for the compiler benefict.
static void matris_muller ( const double a[][3], const double x[], double b[] );
int main()
{
// Just to be sure I divided the values in groups of 3.
// Nothing wrong not doing this, but, to me, is clearer.
//
// And... just for optimization sake, declaring as 'static const' will make
// the compiler put those arrays in .rodata section in compile time.
static const double a_cap[][3] = { { 1, 0, 0 }, { 0, 2, 0 }, { 0, 0, 3 } };
static const double x[3] = { 1, 1, 1 };
double b1[3]; // FIXED: We have to allocate all 3 doubles! This time, in the stack.
matris_muller ( a_cap, x, b1 );
for ( int i = 0 ; i < 3; ++i )
std::cout << b1[i] << '\n'; // std::endl is used to flush the stream.
// for std::cout, '\n' will do the same, but cheaper.
}
// FIXED: The name of the function was wrong!
void matris_muller ( const double a[][3], const double x[], double b[] )
{
for ( int i = 0 ; i < 3 ; ++i )
for ( int j = 0 ; j < 3; ++j )
b[j] += a[i][j] * x[j];
}