Вопрос школьника по предмету Информатика
Задача для языка Free Pascal
Описать функцию S(x,eps), вычисляющую значение суммы ряда в точке с указанной точностью eps, если формула суммы:
S= x — x/2 + x/3 — x/4 + x/5 — …, ряд знакопеременный
Обратиться с координатами точек x = [-0,5;0,5], шаг = 0,1
Ответ учителя по предмету Информатика
function F(x,eps:double):double;
var
s0,s1,sgn,d:real;
begin
s1:=x; d:=1; sgn:=1;
repeat
s0:=s1; d:=d+1; sgn:=-sgn;
s1:=s0+sgn*x/d
until abs(s1-s0)<=eps;
f:=s1
end;
var
x:double;
begin
x:=-0.5;
while x<=0.5 do begin
Writeln(x:4:1,F(x,1e-7):14:7);
x:=x+0.1
end
end.
Результат
-0.5 -0.3465736
-0.4 -0.2772589
-0.3 -0.2079442
-0.2 -0.1386295
-0.1 -0.0693148
0.0 0.0000000
0.1 0.0693148
0.2 0.1386295
0.3 0.2079442
0.4 0.2772589
0.5 0.3465736
Похожие вопросы от пользователей
Fill in the blanks with the verbs ‘to offer’ or ‘to suggest’ in the correct form.
1. My neighbour — to take us to the station in his car. 2. I — that you shouldn’t buy cheap things: they don’t last. 3. That is my final price, I can’t — you more. 4. The monitor — that we raise this question at the next meeting. 5. The boy was so eager to see the show that I — my ticket to him. 6. He — that we shouldn’t break the news to Mother yet: it will upset her. 7. She was free that day and — to help me with the arrangements for the party. 8. I know, he won’t sell the canvas even if he — a very high price. 9. Who — the plan?