Class: HilbertMatrix
- Inherits:
-
Object
- Object
- HilbertMatrix
- Defined in:
- ext/hilbert/hilbert.c
Instance Method Summary collapse
Instance Method Details
#execute(a, b, n) ⇒ Object
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 |
# File 'ext/hilbert/hilbert.c', line 19
static VALUE
execute(VALUE self, VALUE a, VALUE b, VALUE n)
{
GET_FLOAT(a);
GET_FLOAT(b);
GET_FLOAT(n);
int i;
double s1=0.0, s2=0.0, d;
double x, y[n+1];
d=(b-a)/(double)n;
for(i=0; i<=n; i++)
{
x=(double)i*d+a;
y[i]=func(x);
}
for(i=1; i<=n-1; i+=2)
{
s1+=y[i];
}
for(i=2; i<=n-2; i+=2)
{
s2+=y[i];
}
double s=(y[0]+4.0*s1+2.0*s2+y[n])*d/3.0;
return DBL2NUM(s);
}
|
#func(x) ⇒ Object
11 12 13 14 15 16 |
# File 'ext/hilbert/hilbert.c', line 11
static VALUE
rb_func(VALUE self, VALUE x)
{
GET_FLOAT(x);
return(DBL2NUM((x * x)/2));
}
|