И у тебя также границы N не соответствуют в кодах на R и на Python.
Я поправлял, вывел график, как в коде на R.
>>> import math as m
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>>
>>> def A(x):
... return( m.log(3 + m.sqrt(1 + x) ))
...
>>> def B(x):
... return( m.exp(-x / 2) )
...
>>> def C(x):
... return ( m.sqrt((3 - x) / 2) )
...
>>> def F(x):
... return ( 2 - abs(1 - x) )
...
>>>
>>> def range_float(start, end, step, eps=0.000001):
... x = start
... while x <= end + eps:
... yield x
... x += step
...
>>>
>>> def run(n):
... h = 2.4 / (n+1)
... def an(x):
... return (-(2 * A(x) + B(x) * h))
... def bn(x):
... return (4 * A(x) + 2 * C(x) * pow(h,2))
... def cn(x):
... return (-(2 * A(x) - B(x) * h))
... def fn(x):
... return (2 * F(x) * pow(h,2))
...
... #x = np.arange(0.1, 2.5, h)
... x = list(range_float(0.1, 2.5, h))
... print(x, len(x), n)
...
... a = list(map(an, x))
... b = list(map(bn, x))
... c = list(map(cn, x))
... f = list(map(fn, x))
... a[0] = 0; b[0] = 1; c[0] = 0 ; f[0] = 0.8
... a[n+2-1] = 0; b[n+2-1] = 1; c[n+2-1] = 0; f[n+2-1] = 1
... alpha = np.ones(len(x)); beta = np.ones(len(x))
... alpha[0] = -c[0]/b[0]
... beta[0] = f[0]/b[0]
... # i = 0
... for i in range(n + 1):
... alpha[i] = (-1) * (c[i]) / (a[i] * alpha[i - 1] + b[i])
... beta[i] = (f[i] - a[i] * beta[i - 1]) / (a[i] * alpha[i - 1] + b[i])
... y = np.ones(len(x))
... y[0] = 0.8
... y[-1] = 1
... for i in reversed(range(n + 1)):
... y[i] = alpha[i] * y[i+1] + beta[i]
... print(i, y[i])
... plt.plot(x, y, color='red', marker='o', linestyle='solid')
... plt.show()
...
>>> run(100)
[0.1, 0.12376237623762376, 0.14752475247524752, 0.17128712871287127, 0.19504950495049503, 0.21881188118811878, 0.24257425742574254, 0.2663366336633663, 0.2900990099009901, 0.31386138613861386, 0.33762376237623765, 0.36138613861386143, 0.3851485148514852, 0.408910891089109, 0.4326732673267328, 0.45643564356435656, 0.48019801980198035, 0.5039603960396041, 0.5277227722772279, 0.5514851485148516, 0.5752475247524754, 0.5990099009900992, 0.622772277227723, 0.6465346534653468, 0.6702970297029706, 0.6940594059405943, 0.7178217821782181, 0.7415841584158419, 0.7653465346534657, 0.7891089108910895, 0.8128712871287133, 0.836633663366337, 0.8603960396039608, 0.8841584158415846, 0.9079207920792084, 0.9316831683168322, 0.955445544554456, 0.9792079207920797, 1.0029702970297034, 1.0267326732673272, 1.050495049504951, 1.0742574257425748, 1.0980198019801986, 1.1217821782178223, 1.1455445544554461, 1.16930693069307, 1.1930693069306937, 1.2168316831683175, 1.2405940594059413, 1.264356435643565, 1.2881188118811888, 1.3118811881188126, 1.3356435643564364, 1.3594059405940602, 1.383168316831684, 1.4069306930693077, 1.4306930693069315, 1.4544554455445553, 1.478217821782179, 1.5019801980198029, 1.5257425742574267, 1.5495049504950504, 1.5732673267326742, 1.597029702970298, 1.6207920792079218, 1.6445544554455456, 1.6683168316831694, 1.6920792079207931, 1.715841584158417, 1.7396039603960407, 1.7633663366336645, 1.7871287128712883, 1.810891089108912, 1.8346534653465358, 1.8584158415841596, 1.8821782178217834, 1.9059405940594072, 1.929702970297031, 1.9534653465346548, 1.9772277227722785, 2.0009900990099023, 2.024752475247526, 2.04851485148515, 2.0722772277227737, 2.0960396039603975, 2.1198019801980212, 2.143564356435645, 2.167326732673269, 2.1910891089108926, 2.2148514851485164, 2.23861386138614, 2.262376237623764, 2.2861386138613877, 2.3099009900990115, 2.3336633663366353, 2.357425742574259, 2.381188118811883, 2.4049504950495066, 2.4287128712871304, 2.452475247524754, 2.476237623762378, 2.5000000000000018] 102 100
100 1.00478041936
99 1.00953665589
98 1.01426507668
97 1.01896200308
96 1.02362371461
95 1.02824645232
94 1.03282642181
93 1.03735979586
92 1.04184271668
91 1.04627129793
90 1.05064162649
89 1.05494976396
88 1.05919174799
87 1.06336359342
86 1.06746129324
85 1.0714808194
84 1.07541812352
83 1.07926913745
82 1.08302977369
81 1.08669592576
80 1.09026346844
79 1.09372825795
78 1.09708613203
77 1.10033290992
76 1.10346439238
75 1.10647636149
74 1.10936458054
73 1.11212479381
72 1.11475272624
71 1.11724408318
70 1.11959454999
69 1.12179979169
68 1.1238554525
67 1.12575715539
66 1.12750050162
65 1.1290810702
64 1.13049441738
63 1.13173607609
62 1.13280155536
61 1.13368633975
60 1.13438588873
59 1.13489563607
58 1.13521098923
57 1.13532732873
56 1.13524000747
55 1.13494435014
54 1.13443565254
53 1.13370918094
52 1.13276017141
51 1.13158382921
50 1.13017532814
49 1.12852980986
48 1.12664238329
47 1.12450812398
46 1.12212207349
45 1.11947923878
44 1.11657459161
43 1.11340306798
42 1.10995956753
41 1.10623895303
40 1.1022360498
39 1.09794564524
38 1.09336248831
37 1.08848128905
36 1.08331247225
35 1.07786856524
34 1.07216192969
33 1.06620476327
32 1.06000910119
31 1.05358681794
30 1.04694962893
29 1.04010909222
28 1.03307661028
27 1.02586343174
26 1.01848065318
25 1.01093922093
24 1.00324993288
23 0.995423440326
22 0.987470249781
21 0.979400724824
20 0.971225087952
19 0.962953422419
18 0.954595674092
17 0.946161653285
16 0.937661036609
15 0.929103368804
14 0.92049806456
13 0.911854410343
12 0.90318156619
11 0.89448856751
10 0.885784326854
9 0.87707763568
8 0.868377166095
7 0.85969147258
6 0.851028993693
5 0.842398053754
4 0.833806864505
3 0.825263526745
2 0.816776031948
1 0.808352263847
0 0.8
>>>