![]()
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Текст программы. repeat. repeat ⇐ ПредыдущаяСтр 3 из 3 Текст программы
program Lab4; {$APPTYPE CONSOLE} uses SysUtils;
type Func=function (x:Real):Real;
function Sum(f:Func;a,b:Real;n:Integer):Real; var dx:Real; i:Integer; begin dx:=(b-a)/n; Result:=0; for i:=0 to n-1 do Result:=Result+dx*f(a+i*dx+dx/2); end;
function Integr(f:Func;a,b,MaxError:Real):Real; var n:Integer; Prev:Real; begin n:=8; Result:=Sum(f,a,b,n); repeat Prev:=Result; n:=n*2; Result:=Sum(f,a,b,n); until Abs(Result-Prev)<MaxError; end;
procedure PrintIntegr(f,G:Func); var a,b:Real; ch:Char; begin repeat Write('vvedite otrezok inegrirovaniya: '); ReadLn(a,b);
Writeln('Priblizhennoe znachenie integrala'), Integr(f,a,b,1e-6):1:6,'+-',1e-6:1:6); if @G<>nil then Writeln('Tochnoe znachenie integrala '), G(b)-G(a):1:10);
Write('Continued? (Y/N) ? '); Readln(ch); until UpCase(ch)='N'; end;
function f1(x:Real):Real; begin f1:=x*sin(x) end; function G1(x:Real):Real; begin G1:=sin(x)-x*cos(x) end;
function f2(x:Real):Real; begin f2:=sqr(cos(x)) end; function G2(x:Real):Real; begin G2:=x/2+sin(2*x)/4 end;
function f3(x:Real):Real; begin f3:=sin(x)/x end;
function f4(x:Real):Real; begin f4:=exp(sqr(x)) end;
var n:Integer; Loop:Boolean; begin Loop:=True; while Loop do begin Writeln('1. integral of function x*sin(x)'); Writeln('2. integral of function sqr(cos(x))'); Writeln('3. integral of function sin(x)/x'); Writeln('4. integral of function exp(sqr(x))'); Writeln('5. exit'); Write('viberite punkt menu: '); Readln(n); Writeln; case n of 1:PrintIntegr(f1,G1); 2:PrintIntegr(f2,G2); 3:PrintIntegr(f3,nil); 4:PrintIntegr(f4,nil); 5:Loop:=False; end; Writeln; end; readln; end.
end.
Тест
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|