10 for in 10 end print -2 answ for in 10 Math exp answ Math exp end pr

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
n = 10.0
x = []
h = 1.0/n
for i in 0 .. 10
x[i] = h * i
end
print "x:\n", x, "\n"
p = 3.0
q = -2.0
d = []
answ = []
for i in 0 .. 10
d[i] = 2 * h * h * Math.exp(x[i])
answ[i] = Math.exp(x[i])
end
print "answ:\n", answ, "\n"
a = 1.0 - p * h / 2.0
b = q * h * h - 2.0
c = 1.0 + p * h / 2.0
y = []
y[0] = 1
y[n] = Math.exp(1)
alpha = []
betha = []
alpha[1] = -c / b
betha[1] = d[i] / b
for i in 2..(n-1)
alpha[i] = - c / (a * alpha[i-1] + b)
betha[i] = (d[i] - a * betha[i-1]) / (a * alpha[i-1] + b)
end
print alpha, "\n"
print betha, "\n"
y[n-1] = betha[n-1]
i = n - 2
while i > 0
y[i] = alpha[i] * y[i+1] + betha[i]
i -= 1
end
print "y:\n", y, "\n"
answ.each {|x| }