include stdio include conio include math include iostream define defin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <iostream.h>
#define h 0.1
#define N 10
double K(double x,double y)
{
return (x+1)*exp(x*y)*sqrt(x+9);
}
double f(double x)
{
return exp(x);
}
void main()
{
int i,j,m,s;
double c[N+1], y[N+1], a[N+1][N+1], b[N+1], p, max,d,r;
system("cls");
c[0]=c[N]=h/3;
for(i=1;i<N;i++)
{
if (i%2==0) c[i]=2*h/3;
else c[i]=4*h/3;
}
for(i=0;i<=N;i++)
{
b[i]=f(h*i);
for(j=0;j<=N;j++)
if (i==j) a[i][j]=c[j]*K(i*h,j*h)+1;
else a[i][j]=c[j]*K(i*h,j*h);
}
for(m=0;m<=N ;m++)
{
for(j=m;j<=N;j++)
{
max=fabs(a[i][j]);
for(i=j;i<=N;i++)
{
if(fabs(a[i][j])>=max)
{
max=fabs(a[j][j]);
s=i;
}
}
for(i=m;i<=N;i++)
{
max=a[j][i];
a[j][i]=a[s][i];
a[s][i]=max;
}
max=b[j];
b[j]=b[s];
b[s]=max;
}
for(i=m+1;i<=N;i++)
{
if(a[i][m]!=0)
{
d=(-1)*a[m][m]/a[i][m];
a[i][m]=0;
for(j=m+1;j<=N;j++)
{
a[i][j]=a[i][j]*d+a[m][j];
}
b[i]=b[i]*d+b[m];
}
}
}
for(i=0;i<=N;i++)
y[i]=0.0;
for(i=N;i>=0;i--)
{for(j=N;j>=0;j--)
r+=a[i][j]*y[j];
y[i]=(b[i]-r)/a[i][i];
r=0;}
for(i=0;i<=N;i++)
printf("y(%3.1f)=%.3f\n",h*i,y[i]);
printf("\n\nPress any key to continue\n");
_getch();
}