-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09.Romberge.cpp
More file actions
69 lines (59 loc) · 1.09 KB
/
09.Romberge.cpp
File metadata and controls
69 lines (59 loc) · 1.09 KB
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
#include<bits/stdc++.h>
using namespace std;
double T[100][100];
double a=1,b=2,n;
double func(double x)
{
return(1.0/x);
}
double trapezoidal(int n)
{
int i;
double sum = 0,h;
h=(b-a)/n;
for(int i=0;i<=n;i++)
{
if(i==0 || i==n)
{
sum=sum+func(a+i*h);
}
else
{
sum=sum+2*func(a+i*h);
}
}
return ((h/2)*sum);
}
void Romberge(int n)
{
for(int i=1;i<=n;i++)
{
for(int j=0;j<i;j++)
{
if(j==0)
T[i][j]=trapezoidal(pow(2,(i-1))); ///i means number of segment to pass each time
else
T[i][j]=( (pow(4,j)*T[i][j-1])-(T[i-1][j-1]) )/(pow(4,j)-1);
}
}
}
void Display(int n)
{
cout<<"Result is :"<<endl;
for(int i=1;i<=n;i++)
{
for(int j=0;j<i;j++)
{
cout<<fixed<<setprecision(6)<<T[i][j]<<" ";
}
cout<<endl;
}
}
int main()
{
cout<<"Enter the value n :"<<endl;
cin>>n;
Romberge(n);
Display(n);
return 0;
}