x | f (x) |
1 | 1 |
2 | 8 |
3 | 27 |
4 | 64 |
|
| (3) |
|
| (5) |
|
| (8) |
| (9) |
|
|
|
|
| (12) |
| (13) |
x | 0.0 | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1.0 |
f(x) | 0 | 0.0998 | 0.1986 | 0.2955 | 0.3894 | 0.4794 | 0.5646 | 0.6442 | 0.7173 | 0.7833 | 0.8414 |
#include <stdio.h> #define N 11 int main() { double y[N]={0, 0.0998, 0.1986, 0.2955, 0.3894, 0.4794, 0.5646, 0.6442, 0.7173, 0.7833, 0.8414}; double central[N], h=0.1; int i; /* Excluding x=0 and x=1.0 */ for (i=1;i<N-1;i++) central[i]= (y[i+1]-y[i-1])/(2*h); printf (" x Central \n---------------------------\n"); for (i=1;i<N-1;i++) printf ("%lf %lf\n", i*h, central[i]); return 0; } |
|
|
| (16) |
| (17) |
#include <stdio.h> #define N 11 int main() { double y[N]={0, 0.0998, 0.1986, 0.2955, 0.3894, 0.4794, 0.5646, 0.6442, 0.7173, 0.7833, 0.8414}; double central[N], h=0.1; int i; for (i=1;i<N-1;i++) central[i]= (y[i+1]-y[i-1])/(2*h); central[0]=(4*y[1]-y[2]-3*y[0])/(2*h); printf (" x Central \n---------------------------\n"); for (i=0;i<N-1;i++) printf ("%lf %lf\n", i*h, central[i]); return 0; } |
f (x) | ∫f (x) dx |
xα (α ≠ −1) | xα+ 1/(α+ 1) |
1/x | ln x |
ex | ex |
1/(x2 + a2) | arctan x |
sin k x | − cos k x/k |
cos k x | sin k x/k |
|
|
|
|
|
/* Rectangular rule */ #include <stdio.h> double f(double x) {return 4.0/(1.0+x*x) ; } int main() { int i, n; double a=0.0, b=1.0, h, s=0.0 , x ; printf("Number of partitions = "); scanf("%d", &n) ; h = (b-a)/n ; for (i= 0;i<n;i++) s = s + f(a + i*h) ; s=s*h ; printf("Result =%lf\n", s) ; return 0; } |
|
|
/* Trapezoidal rule */ #include <stdio.h> double f(double x) {return 4.0/(1.0+x*x);} int main() { int i, n ; double a=0.0, b=1.0 , h, s=0.0, x; printf("Enter number of partitions = "); scanf("%d", &n) ; h = (b-a)/n ; for (i=1;i<=n-1;i++) s = s + f(a + i*h); s=h/2*(f(a)+f(b))+ h* s; printf("%20.12f\n", s) ; return 0; } |
| (21) |
|
|
|
| (29) |
|
|
|
/* Simpson's rule */ #include <stdio.h> #include <math.h> double f(double x) {return 4.0/(1.0+x*x);} int main() { int i, n ; double a=0.0, b=1.0 , h, s1=0.0, s2=0.0, s3=0.0, x; printf("Enter number of partitions = "); scanf("%d", &n) ; h = (b-a)/(2.0*n) ; s1 = (f(a)+ f(b)); for (i=1; i<2*n; i=i+2) s2 = s2 + f(a + i*h); for (i=2; i<2*n; i=i+2) s3 = s3 + f(a + i*h); printf("%20.12lf\n", (h/3.0)*(s1+ 4.0*s2 + 2.0*s3)) ; return 0; } |
|
|
|
|
|