Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Uses GraphABC;
- function func(x: double): double;
- begin
- Result:=x * exp(x)*sin(x);;
- end;
- function f2(x, h: double): double;
- begin
- Result:=(func(x + h) - 2 * func(x) + func(x - h)) / (h * h);
- end;
- var
- n, w, h, height, length, mastx, masty, i: integer;
- a, b, h1, e, S, f2max, i1, check, maxfunc: double;
- conv: string;
- begin
- w:=1900; h:=1000; length:= w - 50; height:= h - 100; a:= 0; b:= 1; n:=48; e:=0.001;
- setwindowwidth(w);
- setwindowheight(h);
- writeln('Нахождение определенного интеграла функции f(x)=x*e^(x)*sin(x) на отрезке [0;1]. Отрезок разбивается на 48 частей.');
- while(true) do
- begin
- h1:= (b - a) / n;
- S:= h1 * (func(a) + func(b)) / 2;
- for i:=0 to n-1 do
- S:= S + func(a + h1 * i)*h1;
- f2max:= f2(a, h1);
- for i:=0 to n-1 do
- if f2(a + h1 * i, h1) > f2max then f2max:= f2(a + h1 * i, h1);
- check:=f2max * power(b - a, 3) / (12 * n*n);
- if check>e then n:= n + 5
- else
- begin
- writeln('Значение интеграла = ', S);
- break;
- end;
- end;
- mastx:= floor(length/n);
- maxfunc:= func(a);
- for i:=0 to n-1 do
- if (func(a + i * h1) > maxfunc) then
- maxfunc:= func(a + i * h1);
- if (func(b) > maxfunc) then
- maxfunc:= func(b);
- masty:= floor(height / maxfunc);
- writeln('Нажмите Enter, чтобы вывести диаграмму.');
- readln();
- ClearWindow;
- line(30, 30, 30, 30 + height);
- line(30, 30, 25, 40);
- line(30, 30, 35, 40);
- line(30, 30 + height, 20 + length, 30 + height);
- line(20 + length, 30 + height, length + 15, 25 + height);
- line(20 + length, 30 + height, length + 15, 35 + height);
- textout(length + 20, 45 + height, 'x');
- textout(40, 30, 'f(x)');
- i1:=0;
- while i1<1 do
- begin
- line(30 + floor(i1 * length), 20 + height, 30 + floor(i1 * length), 40 + height);
- conv:=floattostr(i1);
- textout(30 + floor(i1 * length), 45 + height, conv);
- line(20, 30 + height - floor(func(i1) * masty), 40, 30 + height - floor(func(i1) * masty));
- conv:=floattostr(func(i1));
- textout(5, 30 + height - floor(func(i1) * masty), conv);
- i1:=i1+0.2;
- end;
- for i:=0 to n-1 do
- begin
- line(30 + floor(i * mastx), 30 + height, 30 + floor(i * mastx), 30 + height - floor(func(a+i*h1) * masty));
- line(30 + floor(i * mastx), 30 + height - floor(func(a+i*h1) * masty), 30 + floor((i+1) * mastx), 30 + height - floor(func(a+i*h1) * masty));
- line(30 + floor((i+1) * mastx), 30 + height, 30 + floor((i+1) * mastx), 30 + height - floor(func(a+i*h1) * masty));
- end;
- readln();
- ClearWindow;
- writeln('Нажмите Enter, чтобы вывести график функции.');
- readln();
- ClearWindow;
- line(30, 30, 30, 30 + height);
- line(30, 30, 25, 40);
- line(30, 30, 35, 40);
- line(30, 30 + height, 20 + length, 30 + height);
- line(20 + length, 30 + height, length + 15, 25 + height);
- line(20 + length, 30 + height, length + 15, 35 + height);
- textout(length + 20, 45 + height, 'x');
- textout(40, 30, 'f(x)');
- i1:=0;
- while i1<1 do
- begin
- line(30 + floor(i1 * length), 20 + height, 30 + floor(i1 * length), 40 + height);
- conv:=floattostr(i1);
- textout(30 + floor(i1 * length), 45 + height, conv);
- line(20, 30 + height - floor(func(i1) * masty), 40, 30 + height - floor(func(i1) * masty));
- conv:=floattostr(func(i1));
- textout(5, 30 + height - floor(func(i1) * masty), conv);
- i1:=i1+0.2;
- end;
- for i:=0 to n-1 do
- begin
- line(30 + floor(i * mastx), 30 + height - floor(func(a+i*h1) * masty), 30 + floor((i+1) * mastx), 30 + height - floor(func(a+(i+1)*h1) * masty));
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement