Entry 3578

substitute() function for gaussian elimination. It's actually Pike, not C.

   

Submitted by anonymous on April 19, 2010 at 3:10 p.m.
Language: C. Code size: 313 bytes.

int|array(float) substitute(array(array(float)) a)
{
	int j, k;
	float t;
	int N = sizeof(a);
	array(float) x = allocate(N);
	for(j=(N-1); j>=0; j--) {
		t = 0.0;
		for(k=(j+1); k<N; k++) {
			t += a[j][k]*x[k];
		}
		if(a[j][j] == 0.0) { return 0; }
		x[j] = (a[j][N]-t)/a[j][j];
	}
	return x;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).