tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
43
Task/Numerical-integration/PL-I/numerical-integration.pli
Normal file
43
Task/Numerical-integration/PL-I/numerical-integration.pli
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
integrals: procedure options (main);
|
||||
|
||||
/* The function to be integrated */
|
||||
f: procedure (x) returns (float);
|
||||
declare x float;
|
||||
return (3*x**2 + 2*x);
|
||||
end f;
|
||||
|
||||
declare (a, b) float;
|
||||
declare (rect_area, trap_area, Simpson) float;
|
||||
declare (d, dx) fixed decimal (10,2);
|
||||
declare (l, r) float;
|
||||
declare (S1, S2) float;
|
||||
|
||||
l = 0; r = 5;
|
||||
a = 0; b = 5; /* bounds of integration */
|
||||
dx = 0.05;
|
||||
|
||||
/* Rectangle method */
|
||||
rect_area = 0;
|
||||
do d = a to b by dx;
|
||||
rect_area = rect_area + dx*f(d);
|
||||
end;
|
||||
put skip data (rect_area);
|
||||
|
||||
/* trapezoid method */
|
||||
trap_area = 0;
|
||||
do d = a to b by dx;
|
||||
trap_area = trap_area + dx*(f(d) + f(d+dx))/2;
|
||||
end;
|
||||
put skip data (trap_area);
|
||||
|
||||
/* Simpson's */
|
||||
S1 = f(a+dx/2);
|
||||
S2 = 0;
|
||||
do d = a to b by dx;
|
||||
S1 = S1 + f(d+dx+dx/2);
|
||||
S2 = S2 + f(d+dx);
|
||||
end;
|
||||
Simpson = dx * (f(a) + f(b) + 4*S1 + 2*S2) / 6;
|
||||
put skip data (Simpson);
|
||||
|
||||
end integrals;
|
||||
Loading…
Add table
Add a link
Reference in a new issue