home *** CD-ROM | disk | FTP | other *** search
- (*****************************************************************************)
- (* INTEGRAL.INC *)
- (* *)
- (* Berechnung eines bestimmten Integrals von f *)
- (*****************************************************************************)
-
- PROCEDURE integrate;
-
- TYPE integrtyp = (flaeche,rotationsvolumen,mantelflaeche,bogenlaenge);
-
- VAR a,b,g,err,i,lasti : REAL;
- k : INTEGER;
- typ : integrtyp;
- key : CHAR;
-
- FUNCTION simpson (a,b :REAL; k :INTEGER; typ : integrtyp) : REAL;
-
- VAR h,s : REAL;
- i : INTEGER;
-
- FUNCTION integrand(x : REAL ; typ : integrtyp) : REAL;
-
- BEGIN
- CASE typ OF
- flaeche : integrand := fn(x,0);
- rotationsvolumen : integrand := pi*Sqr(fn(x,0));
- mantelflaeche : integrand := 2.0*pi*fn(x,0)*Sqrt(1.0+Sqr(fn(x,1
- )));
- bogenlaenge : integrand := Sqrt(1.0+Sqr(fn(x,1)))
- END
- END;
-
- BEGIN
- h := (b-a)/(k+k);
- s := integrand(a,typ) + integrand(b,typ);
- FOR i:=0 TO k-1 DO
- s := s + 4*integrand(a+(i+i+1)*h,typ);
- FOR i:=1 TO k-1 DO
- s := s + 2*integrand(a+2*i*h,typ);
- simpson := s * h/3;
- END;
-
- BEGIN
- Clrscr;
- Writeln ('Berechnung des Integrals von f(x)');
- REPEAT
- Writeln;
- formulaln (a,'von a = ');
- formulaln (b,'bis b = ');
- UNTIL a < b;
- REPEAT
- formulaln (g,'mit relativer Genauigkeit g = ');
- UNTIL g > 0.0;
- Writeln;
- Writeln;
- Writeln('Welche Integration soll ausgefuehrt werden ?');
- Writeln;
- Writeln(' Flaechenintegral : <F>');
- Writeln(' Rotationsvolumen : <R>');
- Writeln(' Mantelflaeche : <M>');
- Writeln(' Bogenlaenge : <B>');
- Writeln;
- Write(' Bitte waehlen : ');
- REPEAT
- Read(kbd,key);
- key := Upcase(key)
- UNTIL key IN ['F','R','B','M'];
- Writeln(key);
- Writeln;
- Writeln;
- CASE key OF
- 'F' : typ := flaeche;
- 'R' : typ := rotationsvolumen;
- 'M' : typ := mantelflaeche;
- 'B' : typ := bogenlaenge
- END;
- k := 4;
- lasti := simpson (a, b, 2, typ);
- REPEAT
- i := simpson (a, b, k, typ); (* Simpson-Naeherung *)
- err := Abs ((i-lasti)/i); (* relativer Fehler *)
- lasti := i;
- k := k * 2 (* Stuetzstellen verdoppeln *)
- UNTIL (err <= g) OR (k > maxiter);
- IF k <= maxiter
- THEN
- BEGIN
- Writeln ('Integral: I = ', i:m:n);
- Writeln;
- Writeln ('relativer Fehler: dI = ', err:m:n);
- Writeln;
- END
- ELSE
- BEGIN
- Writeln ('Maximale Anzahl von Iterationen ueberschritten!');
- Writeln ('Integral ungefaehr: I = ', i:m:n);
- END
- END;
-